Package 'swadlr'

Title: Access the EPI State of Working America Data Library API
Description: Provides functions to retrieve data from the Economic Policy Institute's State of Working America Data Library (SWADL) API. Enables users to explore available indicators, measures, and dimensions, and to fetch time series data at national, regional, and state levels.
Authors: Ben Zipperer [aut, cre], Economic Policy Institute [cph, fnd]
Maintainer: Ben Zipperer <[email protected]>
License: MIT + file LICENSE
Version: 0.2.0
Built: 2026-05-12 09:02:39 UTC
Source: https://github.com/economic/swadlr

Help Index


Clear the swadlr cache

Description

Clears all cached metadata from the current R session. This includes cached topics, indicators, measures, dimensions, and sources. Use this function if you want to refresh metadata from the API.

Usage

clear_swadlr_cache()

Value

Invisible NULL.

Examples

clear_swadlr_cache()

Get time series data from SWADL

Description

Retrieves time series data from the EPI State of Working America Data Library API.

Usage

get_swadl(
  indicator,
  measure,
  date_interval = c("year", "month"),
  geography = "national",
  dimension = "overall",
  date = NULL
)

Arguments

indicator

Indicator ID (e.g., "hourly_wage_percentiles"). Use swadl_id_names() to see available indicators.

measure

Measure ID (e.g., "nominal_wage"). Use swadl_id_names() or swadl_indicator() to see available measures.

date_interval

Either "year" or "month". Defaults to "year".

geography

A geography specification. Accepts state names (e.g., "California"), abbreviations (e.g., "CA"), region names (e.g., "Midwest"), division names (e.g., "Pacific"), or API IDs (e.g., "state06"). Defaults to "national".

dimension

Dimension specification. Can be:

  • "overall": Returns aggregate data without demographic breakdown

  • A dimension ID (e.g., "wage_percentile"): Returns all values for that dimension

  • A list with named and/or unnamed elements:

    • Named elements filter to specific values: list("wage_percentile" = "wage_p50")

    • Unnamed elements return all values: list("wage_percentile")

    • Multiple dimensions can be cross-tabulated, but only one dimension can return all values; the others must specify values: list("gender" = "gender_male", "age_group")

date

Optional date filter. Can be:

  • NULL (default): All available dates

  • A single date (character or Date): Returns only that date

  • A vector of two dates: Returns dates in that range (inclusive)

Value

A tibble with columns:

  • date: Observation date

  • value: The observed value

  • geography: Geography ID

  • One column per dimension in the request, containing dimension value IDs

See Also

swadl_indicator() for indicator details, swadl_id_names() to list indicators, measures, and dimensions.

Examples

# Median hourly wage over time
get_swadl(
  "hourly_wage_percentiles",
  "nominal_wage",
  dimension = list("wage_percentile" = "wage_p50")
)

# All wage percentiles
get_swadl(
  "hourly_wage_percentiles",
  "nominal_wage",
  dimension = "wage_percentile"
)

# Employment rate for males by age group
get_swadl(
  "labor_force_emp",
  "percent_emp",
  dimension = list("gender" = "gender_male", "age_group")
)

# Filter to specific date range
get_swadl(
  "hourly_wage_percentiles",
  "nominal_wage",
  dimension = "wage_percentile",
  date = c("2000-01-01", "2024-01-01")
)

Find available data across all indicators

Description

Searches across all indicators to find which data is available matching specified criteria. Useful for answering questions like "Which indicators have state-level data by race?"

Usage

swadl_availability(
  indicator = NULL,
  measure = NULL,
  date_interval = NULL,
  geo_level = NULL,
  dimensions = NULL,
  dimensions_match = c("exact", "all", "any")
)

Arguments

indicator

Character vector of indicator IDs to filter to. If NULL (the default), includes all indicators.

measure

Character vector of measure IDs to filter to. If NULL (the default), includes all measures.

date_interval

Character vector of date intervals to filter to. Valid values are "year", "quarter", and "month". If NULL (the default), includes all date intervals.

geo_level

Character vector of geographic levels to filter to. Valid values are "national", "state", and "division". If NULL (the default), includes all geographic levels.

dimensions

Character vector of dimension IDs to match. How these are matched depends on dimensions_match. If NULL (the default), no dimension filtering is applied.

dimensions_match

How to match the dimensions argument:

"exact"

The dimensions column must exactly match the provided dimensions (order-insensitive). For example, c("gender", "race") matches "gender × race" but not "age_group × gender × race".

"all"

The dimensions column must contain ALL provided dimensions (may contain more). For example, c("gender", "race") matches both "gender × race" and "age_group × gender × race".

"any"

The dimensions column must contain ANY of the provided dimensions. For example, c("gender", "race") matches "gender", "race", "gender × race", and "age_group × gender".

Value

A tibble with columns:

indicator_id

Indicator identifier

indicator_name

Human-readable indicator name

date_interval

"year", "quarter", or "month"

measure_id

Measure identifier

geo_level

"national", "state", or "division"

dimensions

Dimension combination (e.g., "gender × race") or "overall" for aggregate data

date_start

Start of available date range

date_end

End of available date range

See Also

swadl_indicator() for detailed information about a single indicator, swadl_id_names() to list all indicators.

Examples

# Find all indicators with state-level gender data
swadl_availability(geo_level = "state", dimensions = "gender",
  dimensions_match = "any")

# Find indicators with a specific measure
swadl_availability(measure = "percent_emp")

# Find all availability for a specific indicator
swadl_availability(indicator = "hourly_wage_percentiles")

# Find indicators with exact "gender × race" combinations at national level
swadl_availability(geo_level = "national",
  dimensions = c("gender", "race"), dimensions_match = "exact")

List ID-name mappings for SWADL metadata

Description

Returns a tibble of ID-name mappings for SWADL metadata. Use this to understand what each ID represents.

Usage

swadl_id_names(
  what = c("topics", "indicators", "measures", "dimensions", "geographies"),
  topic = NULL,
  indicator = NULL
)

Arguments

what

The type of metadata to list. One of:

"topics"

Broad categories that group related indicators

"indicators"

Specific data series that can be retrieved with get_swadl()

"measures"

Ways of presenting indicator data (e.g., nominal vs real wages)

"dimensions"

Demographic categories for subsetting data (e.g., gender, race)

"geographies"

Geographic units (national, regions, divisions, states)

topic

For what = "indicators", optionally filter to a specific topic ID.

indicator

For what = "measures" or what = "dimensions", optionally filter to those available for a specific indicator ID.

Value

A tibble. The columns depend on what:

topics

id, name

indicators

id, name, topic_id, updated_date

measures

id, name, format

dimensions

dimension_id, dimension_name, value_id, value_name

geographies

id, level, name, abbr

See Also

swadl_indicator() for detailed information about a single indicator, get_swadl() for fetching time series data.

Examples

# List all topics
swadl_id_names("topics")

# List all indicators
swadl_id_names("indicators")

# List indicators for a specific topic
swadl_id_names("indicators", topic = "wages")

# List measures for a specific indicator
swadl_id_names("measures", indicator = "hourly_wage_percentiles")

# List dimensions
swadl_id_names("dimensions")

# List geographies
swadl_id_names("geographies")

Get detailed information about an indicator

Description

Returns detailed information about a specific indicator including available measures, dimension combinations, date ranges, geographic availability, and sources.

Usage

swadl_indicator(indicator)

Arguments

indicator

The indicator ID (e.g., "hourly_wage_percentiles"). Use swadl_id_names() to see available indicators.

Value

An S3 object of class swadl_indicator_info with the following components:

id

Indicator identifier

name

Human-readable indicator name

topic

Topic ID the indicator belongs to

updated

Date the indicator was last updated

measures

Tibble of available measures with columns: id, name, format

availability

Tibble of availability information with columns: date_interval, measure_id, geo_level, dimensions, date_start, date_end. The dimensions column contains dimension IDs joined with x (using multiplication sign), or "overall" for aggregate data.

sources

Tibble of sources with columns: measure_id, source, url

See Also

swadl_id_names() to list available indicators, measures, and dimensions.

Examples

# Get information about hourly wage percentiles
info <- swadl_indicator("hourly_wage_percentiles")
print(info)

# Access specific components
info$measures
info$availability