Type: Package
Title: Download Time Series Data from the U.S. Bureau of Labor Statistics
Version: 0.4
Description: These functions provide a convenient interface for downloading data from the U.S. Bureau of Labor Statistics https://www.bls.gov. The functions in this package utilize flat files produced by the Bureau of Labor Statistics, which contain full series history. These files include employment, unemployment, wages, prices, industry and occupational data at a national, state, and sub-state level, depending on the series. Individual functions are included for those programs which have data available at the state level. The core functions provide direct access to the Current Employment Statistics (CES) https://www.bls.gov/ces/, Local Area Unemployment Statistics (LAUS) https://www.bls.gov/lau/, Occupational Employment and Wage Statistics (OEWS) https://www.bls.gov/oes/ and Alternative Measures of Labor Underutilization (SALT) https://www.bls.gov/lau/stalt.htm data produced by the Bureau of Labor Statistics.
License: MIT + file LICENSE
Encoding: UTF-8
Depends: R (≥ 4.1.0)
Imports: data.table (≥ 1.16), httr (≥ 1.4.7), dplyr (≥ 1.1), stringr (≥ 1.5), lubridate (≥ 1.9), rvest (≥ 1.0.4), readxl (≥ 1.4.5), sf (≥ 1.0), tidyselect (≥ 1.2), tigris (≥ 2.0), zoo (≥ 1.8), htmltools, rstudioapi
RoxygenNote: 7.3.3
Suggests: ggplot2, knitr, mapgl, rmarkdown, tidyr, gt
VignetteBuilder: knitr
URL: https://schmidtdetr.github.io/BLSloadR/
Config/Needs/website: rmarkdown
LazyData: true
NeedsCompilation: no
Packaged: 2026-02-13 23:20:10 UTC; deschmidt
Author: Nevada Department of Employment, Training, and Rehabilitation [cph], David Schmidt [aut, cre], Mark Rembert [aut]
Maintainer: David Schmidt <deschmidt@detr.nv.gov>
Repository: CRAN
Date/Publication: 2026-02-13 23:40:02 UTC

Area Lookup Tables (QCEW)

Description

A data frame containing area codes, titles, and additional geographic information about valid areas for the Quarterly Census of Employment and Wages (QCEW).

This table is primarily used internally by 'BLSloadR' functions to add human-readable area titles or define valid area lookups.

Usage

data(area_lookup)

Format

A data frame with 4649 rows and 5 columns:

Details

Area codes are five characters long. When all numeric characters, this is a state-county FIPS, with statewide data using a "000" as the county FIPS. Other aggregations include various alphabetic characters to aid in the classification of different regions.

Source

https://www.bls.gov/cew/classifications/areas/qcew-area-titles.htm

Examples

# Load the lookup table
data(area_lookup)

# Find the area codes for all Statewide areas
state_codes <- area_lookup[area_lookup$area_type == "State", ]

# Get all Metropolitan Statistical Area codes including Arkansas.
ar_codes <- area_lookup |> 
dplyr::filter(grepl("AR", specified_region) &
 area_type == "Metropolitan Statistical Area")

Get the current BLSloadR Cache Directory

Description

Displays the path currently being used for caching. This will check the 'BLS_CACHE_DIR' environment variable, falling back to the default system cache directory if the variable is not set.

Usage

bls_get_cache_dir()

Value

A character string of the cache path.


Display BLS Dataset Overview

Description

Fetches and displays the overview text file for a BLS dataset. This provides a convenient reference within the R environment without needing to manually find and review the text file on the BLS website.

Usage

bls_overview(
  series_id,
  display_method = "viewer",
  base_url = "https://download.bls.gov/pub/time.series"
)

Arguments

series_id

Character string. The BLS series identifier (e.g., "ln", "cu", "ap")

display_method

Character string. How to display the overview: "viewer" (default), "console", or "popup"

base_url

Character string. Base URL for BLS data (default uses official BLS site)

Value

Invisibly returns the text content. Function is called to use the viewer, console, or as a popup, depending on the 'display_method' argument.

Examples


# Display Average Price Data overview
bls_overview("ap")

# Display consumer price index overview  
bls_overview("cu")

# Display in console instead of viewer
bls_overview("ap", display_method = "console")


Check if Global Caching is Enabled via Environment Variable

Description

Check if Global Caching is Enabled via Environment Variable

Usage

check_bls_cache_env()

Value

Logical value indicating if the environment variable USE_BLS_CACHE is one of TRUE, YES, or 1


Create a BLS data object with diagnostics

Description

This is a helper function to create a list with the additional class 'bls_data_collection' containing data downloaded form the U.S. Bureau of Labor Statistics as well as diagnostic details about the download. It is used invisibly in the package to bundle information about file downloads.

Usage

create_bls_object(
  data,
  downloads,
  data_type = "BLS",
  processing_steps = character(0)
)

Arguments

data

The processed data (data.table/data.frame)

downloads

List of download results from fread_bls()

data_type

Character string describing the type of BLS data (e.g., "CES", "JOLTS", "CPS")

processing_steps

Character vector describing processing steps applied

Value

A bls_data_collection object


Display text content in console.

Description

Helper function used to display content from 'bls_overview' in the console..

Usage

display_in_console(content, series_id)

Arguments

content

Character. Text content to display

series_id

Two-letter series ID for a BLS time series to render in the display.

Value

No object returned, called to render content in console only..


Display text content in popup window.

Description

Helper function used to display content from 'bls_overview' in a popup window.

Usage

display_in_popup(content, series_id)

Arguments

content

Character. Text content to display

series_id

Two-letter series ID for a BLS time series to render in the display.

Value

No object returned, called to render content in popup.


Display text content in Viewer window.

Description

Helper function used to display content from 'bls_overview' in the HTML viewer.

Usage

display_in_viewer(content, series_id)

Arguments

content

Character. Text content to display

series_id

Two-letter series ID for a BLS time series to render in the display.

Value

No object returned, called to render content in HTML viewer.


Helper function for downloading and tracking BLS files

Description

This function is used to pass multiple URLs at the Bureau of Labor Statistics into 'fread_bls()'

Usage

download_bls_files(urls, suppress_warnings = TRUE, cache = FALSE)

Arguments

urls

Named character vector of URLs to download

suppress_warnings

Logical. If TRUE, suppress individual download warnings

cache

Logical. If TRUE, download and cache local copy of files.

Value

Named list of bls_data objects


Download BLS Time Series Data

Description

This function downloads a tab-delimited BLS flat file, incorporating diagnostic information about the file and returning an object with the bls_data class that can be used in the BLSloadR package.

Usage

fread_bls(url, verbose = FALSE, cache = check_bls_cache_env())

Arguments

url

Character string. URL to the BLS flat file

verbose

Logical. If TRUE, prints additional messages during file read and processing.

cache

Logical. If TRUE, uses local persistent caching.

Value

A named list with the data and diagnostics.


Extract data from BLS data object

Description

This is a helper function to extract the data element of a 'bls_data_collection' object.

Usage

get_bls_data(bls_obj)

Arguments

bls_obj

A bls_data_collection object or raw data

Value

The data component of a 'bls_data_collection' object as a data frame.


Get download diagnostics from BLS data object

Description

This is a helper function to extract the download diagnostics element of a 'bls_data_collection' object.

Usage

get_bls_diagnostics(bls_obj)

Arguments

bls_obj

A bls_data_collection object

Value

List of download diagnostics from a bls_data_collection object.


Get summary information from BLS data object

Description

This is a helper function to extract the summary element of a 'bls_data_collection' object. This containes the number of files downloaded, the number of files with potential warnings, and the total number of warnings.

Usage

get_bls_summary(bls_obj)

Arguments

bls_obj

A bls_data_collection object

Value

List of summary information


Download Current Employment Statistics (CES) Data

Description

This function downloads Current Employment Statistics data from the Bureau of Labor Statistics. The data includes national, regional, state, and substate employment statistics. By default, all available areas, data types, and periods are included.

Usage

get_ces(
  states = NULL,
  industry_filter = NULL,
  current_year_only = FALSE,
  transform = TRUE,
  monthly_only = TRUE,
  simplify_table = TRUE,
  suppress_warnings = TRUE,
  return_diagnostics = FALSE,
  cache = check_bls_cache_env()
)

Arguments

states

Character vector of state abbreviations to download (e.g., c("MA", "NY", "CA")). If specified, downloads only these states (all industries, all years). Cannot be combined with industry_filter or current_year_only. Use 'list_ces_states()' to see all available states.

industry_filter

Character string specifying industry category to download. If specified, downloads this industry for all states (2007-present). Cannot be combined with states or current_year_only. Use 'list_ces_industries()' to see all available industry filters.

current_year_only

Logical. If TRUE, downloads the current year file which contains all states and industries for recent years (2006-present). Cannot be combined with states or industry_filter. If FALSE (default), uses other parameters.

transform

Logical. If TRUE (default), converts employment values from thousands to actual counts by multiplying by 1000 for specific data types (codes 1, 6, 26) and removes ", In Thousands" from data type labels.

monthly_only

Logical. If TRUE (default), filters out annual data (period M13).

simplify_table

Logical. If TRUE (default), removes excess columns and creates a date column from Year and Period in the original data.

suppress_warnings

Logical. If TRUE (default), suppress individual download warnings and diagnostic messages for cleaner output during batch processing. If FALSE, returns the data and prints warnings and messages to the console.

return_diagnostics

Logical. If FALSE (default), returns only the data. If TRUE, returns the full bls_data_collection object with diagnostics.

cache

Logical. Uses USE_BLS_CACHE environment variable, or defaults to FALSE. If TRUE, will download a cached file from BLS server and update cache if BLS server indicates an updated file.

Details

**Performance Notes:** The default behavior downloads a very large file (~500MB+) containing all states and industries, which can take several minutes. For faster downloads, consider:

**State Codes:** Use standard two-letter state abbreviations (e.g., "MA", "CA", "NY"). Puerto Rico = "PR", Virgin Islands = "VI", District of Columbia = "DC".

**Industry Filters:** Available options include:

Value

By default, returns a data.table with CES data. If return_diagnostics = TRUE, returns a bls_data_collection object containing data and comprehensive diagnostics.

See Also

list_ces_states() to see available states, list_ces_industries() to see available industry filters, show_ces_options() for a comprehensive overview of filtering options.

Examples


# Fast download: Massachusetts and Connecticut data only (all industries)
ces_states <- get_ces(states = c("MA", "CT"))

# Fast download: Manufacturing data for all states
ces_manufacturing <- get_ces(industry_filter = "manufacturing")

# Fast download: Current year data for all states and industries
ces_current <- get_ces(current_year_only = TRUE)

# Complete dataset (slower - all states, industries, and years)
ces_all <- get_ces()

# Download with full diagnostics if needed
ces_result <- get_ces(states = "MA", return_diagnostics = TRUE)
ces_data <- get_bls_data(ces_result)

# Check for download issues
if (has_bls_issues(ces_result)) {
  print_bls_warnings(ces_result)
}


Download Job Openings and Labor Turnover Survey (JOLTS) Data

Description

This function downloads Job Openings and Labor Turnover data from the U.S. Bureau of Labor Statistics. JOLTS data provides insights into job market dynamics including job openings, hires, separations, quits, and layoffs. Data is available at national, regional, and state levels with various industry and size class breakdowns.

Usage

get_jolts(
  monthly_only = TRUE,
  remove_regions = TRUE,
  remove_national = TRUE,
  suppress_warnings = TRUE,
  return_diagnostics = FALSE,
  cache = check_bls_cache_env()
)

Arguments

monthly_only

Logical. If TRUE (default), excludes annual data (period M13) and includes only monthly observations.

remove_regions

Logical. If TRUE (default), excludes regional aggregates (Midwest, Northeast, South, West) identified by state codes MW, NE, SO, WE.

remove_national

Logical. If TRUE (default), excludes national-level data (state code 00). Set to FALSE to include national data with industry and size class breakdowns.

suppress_warnings

Logical. If TRUE (default), suppress individual download warnings and diagnostic messages for cleaner output during batch processing. If FALSE, returns the data and prints warnings and messages to the console.

return_diagnostics

Logical. If TRUE, returns a bls_data_collection object with full diagnostics. If FALSE (default), returns just the data table.

cache

Logical. Uses USE_BLS_CACHE environment variable, or defaults to FALSE. If TRUE, will download a cached file from BLS server and update cache if BLS server indicates an updated file.

Details

The function performs several data transformations:

Value

By default, returns a data.table with JOLTS data. If return_diagnostics = TRUE, returns a bls_data_collection object containing JOLTS data with the following key columns:

series_id

BLS series identifier

year

Year of observation

period

Time period (M01-M12 for months)

value

JOLTS statistic value (transformed based on data type)

date

Date of observation

state_text

State name

dataelement_text

Type of JOLTS measure (job openings, hires, separations, etc.)

area_text

Geographic area description

sizeclass_text

Establishment size class

industry_text

Industry classification

ratelevel_code

Whether the value is a "Level" (count) or "Rate" (percentage)

periodname

Month name

Examples


# Download state-level JOLTS data (default - returns data directly)
jolts_data <- get_jolts()

# Include national data with industry breakdowns
jolts_national <- get_jolts(remove_national = FALSE)

# Get full diagnostic object if needed
jolts_with_diagnostics <- get_jolts(return_diagnostics = TRUE)
print_bls_warnings(jolts_with_diagnostics)

# View job openings by state for latest period
job_openings <- jolts_data[dataelement_text == "Job openings" & 
                          date == max(date)]


Download Local Area Unemployment Statistics (LAUS) Data

Description

This function downloads Local Area Unemployment Statistics data from the U.S. Bureau of Labor Statistics. Due to the large size of some LAUS datasets (county and city files are >300MB), users must specify which geographic level to download. The function provides access to both seasonally adjusted and unadjusted data at various geographic levels. Additional datasets provide comprehensive non-seasonally-adjusted data for all areas broken out in 5-year increments

Usage

get_laus(
  geography = "state_adjusted",
  monthly_only = TRUE,
  transform = TRUE,
  suppress_warnings = TRUE,
  return_diagnostics = FALSE,
  cache = check_bls_cache_env()
)

Arguments

geography

Character string specifying the geographic level and adjustment type. Default is "state_adjusted". Valid options are:

  • "state_current_adjusted" - Current seasonally adjusted state data

  • "state_unadjusted" - All historical unadjusted state data

  • "state_adjusted" - All historical seasonally adjusted state data (default)

  • "region_unadjusted" - Unadjusted regional and division data

  • "region_adjusted" - Seasonally adjusted regional and division data

  • "metro" - Metropolitan statistical area data

  • "division" - Division-level data

  • "micro" - Micropolitan statistical area data

  • "combined" - Combined statistical area data

  • "county" - County-level data (large file >300MB)

  • "city" - City and town data (large file >300MB)

  • "1990-1994" - Comprehensive unadjusted data for 1990-1994

  • "1995-1999" - Comprehensive unadjusted data for 1995-1999

  • "2000-2004" - Comprehensive unadjusted data for 2000-2004

  • "2005-2009" - Comprehensive unadjusted data for 2005-2009

  • "2010-2014" - Comprehensive unadjusted data for 2010-2014

  • "2015-2019" - Comprehensive unadjusted data for 2015-2019

  • "2020-2024" - Comprehensive unadjusted data for 2020-2024

  • "2025-2029" - Comprehensive unadjusted data for 2025-2029

  • "ST" - Any state two-character USPS abbreviation, plus DC and PR

monthly_only

Logical. If TRUE (default), excludes annual data (period M13) and creates a date column from year and period.

transform

Logical. If TRUE (default), converts rate and ratio measures from percentages to proportions by dividing by 100. Unemployment rates will be expressed as decimals (e.g., 0.05 for 5% unemployment) rather than as whole numbers (e.g. 5).

suppress_warnings

Logical. If TRUE (default), suppress individual download warnings and diagnostic messages for cleaner output during batch processing. If FALSE, returns the data and prints warnings and messages to the console.

return_diagnostics

Logical. If TRUE, returns a bls_data_collection object with full diagnostics. If FALSE (default), returns just the data table.

cache

Logical. Uses USE_BLS_CACHE environment variable, or defaults to FALSE. If TRUE, will download a cached file from BLS server and update cache if BLS server indicates an updated file.

Details

The function joins data from multiple BLS files:

Value

By default, returns a data.table with LAUS data. If return_diagnostics = TRUE, returns a bls_data_collection object containing LAUS data with the following key columns:

series_id

BLS series identifier

year

Year of observation

period

Time period (M01-M12 for months, M13 for annual)

value

Employment statistic value (transformed if transform = TRUE)

date

Date of observation (if monthly_only = TRUE)

area_text

Geographic area name

area_type_code

Code indicating area type

measure_text

Type of measure (unemployment rate, labor force, employment, etc.)

seasonal

Seasonal adjustment status

Examples


# Download state-level seasonally adjusted data (default operation)
laus_states <- get_laus()

# View unemployment rates by state for latest period
unemployment <- laus_states[grepl("unemployment rate", measure_text) & date == max(date)]

# Download unadjusted state data
laus_states_unadjusted <- get_laus(geography = "state_unadjusted")

# Get full diagnostic object if needed
laus_with_diagnostics <- get_laus(return_diagnostics = TRUE)
print_bls_warnings(laus_with_diagnostics)




Get National Current Employment Statistics (CES) Data from BLS

Description

This function downloads and processes national Current Employment Statistics (CES) data from the Bureau of Labor Statistics (BLS). It retrieves multiple related datasets and joins them together to create a comprehensive employment statistics dataset with industry classifications, data types, and time period information.

Usage

get_national_ces(
  dataset_filter = "all_data",
  monthly_only = TRUE,
  simplify_table = TRUE,
  suppress_warnings = TRUE,
  return_diagnostics = FALSE,
  cache = check_bls_cache_env()
)

Arguments

dataset_filter

Character string specifying which dataset to download. Options include:

  • "all_data" (default) - Complete dataset with all series

  • "current_seasonally_adjusted" - Only seasonally adjusted all-employee series

  • "real_earnings_all_employees" - Real earnings data for all employees

  • "real_earnings_production" - Real earnings data for production employees

monthly_only

Logical. If TRUE (default), excludes annual averages (period "M13") and returns only monthly data. If FALSE, includes all periods including annual averages.

simplify_table

Logical. If TRUE (default), removes several metadata columns (series_title, begin_year, begin_period, end_year, end_period, naics_code, publishing_status, display_level, selectable, sort_sequence) and adds a formatted date column. If FALSE, returns the full dataset with all available columns.

suppress_warnings

Logical. If TRUE (default), suppresses download warnings and diagnostics. If FALSE, displays warning output and diagnostic information.

return_diagnostics

Logical. If TRUE, returns a bls_data_collection object with full diagnostics. If FALSE (default), returns just the data table.

cache

Logical. Uses USE_BLS_CACHE environment variable, or defaults to FALSE. If TRUE, will download a cached file from BLS server and update cache if BLS server indicates an updated file.

Details

The function can download one of four specialized national CES datasets based on the dataset_filter parameter:

Additional metadata files are always downloaded and joined:

These datasets are joined together to provide context and labels for the employment statistics. The function uses the enhanced 'download_bls_files()' helper function for robust downloads with diagnostic reporting.

Performance Note: Using specialized datasets (other than "all_data") can significantly reduce download time and file size while still providing comprehensive employment statistics.

Value

By default, returns a data.table with CES data. If return_diagnostics = TRUE, returns a bls_data_collection object containing data and comprehensive diagnostics.

Note

This function requires the following packages: dplyr, data.table, httr, and lubridate (for date formatting when simplify_table=TRUE). The 'fread_bls()' and 'create_bls_object()' helper functions must be available in your environment.

See Also

Please visit the Bureau of Labor Statistics at https://www.bls.gov/ces/ for more information about CES data

Examples


# Get complete monthly CES data with simplified table structure (default)
ces_monthly <- get_national_ces()

# Get only seasonally adjusted data (faster download)
ces_seasonal <- get_national_ces(dataset_filter = "current_seasonally_adjusted")

# Get real earnings data for all employees
ces_real_earnings <- get_national_ces(dataset_filter = "real_earnings_all_employees")

# Get all data including annual averages with full metadata
ces_full <- get_national_ces(dataset_filter = "all_data",
                             monthly_only = FALSE, simplify_table = FALSE)

# Get data with warnings and diagnostic information displayed
ces_with_warnings <- get_national_ces(suppress_warnings = FALSE)

# Get full diagnostic object if needed
data_with_diagnostics <- get_national_ces(return_diagnostics = TRUE)
print_bls_warnings(data_with_diagnostics)




Download Occupational Employment and Wage Statistics (OEWS) Data

Description

This function downloads and joins together occupational employment and wage data from the Bureau of Labor Statistics OEWS program. The data includes employment and wage estimates by occupation and geographic area. Note that OEWS is a large data set (over 6 million rows), so it will require longer to download.

Usage

get_oews(
  simplify_table = TRUE,
  suppress_warnings = TRUE,
  return_diagnostics = FALSE,
  fast_read = TRUE,
  cache = check_bls_cache_env()
)

Arguments

simplify_table

Logical. If TRUE (default), remove columns from the result that are internal BLS references or can be derived from other elements in the table.

suppress_warnings

Logical. If TRUE (default), suppress individual download warnings and diagnostic messages for cleaner output during batch processing. If FALSE, returns the data and prints warnings and messages to the console.

return_diagnostics

Logical. If TRUE, returns a bls_data_collection object with full diagnostics. If FALSE (default), returns just the data table.

fast_read

Logical. If TRUE (default), derives lookup values directly from series_id to avoid reading the series file, to speed download process. With fast_read, the data can download in 17 seconds (depending on bandwidth). Without fast_read, the same download takes 57 seconds.

cache

Logical. Uses USE_BLS_CACHE environment variable, or defaults to FALSE. If TRUE, will download a cached file from BLS server and update cache if BLS server indicates an updated file.

Value

By default, returns a data.table with OEWS data. If return_diagnostics = TRUE, returns a bls_data_collection object containing data and comprehensive diagnostics. The columns in the returned data frame when 'simplify_table = TRUE' are listed below. Unless otherwise specified, all data is returned as a character string to preserve the value of leading and trailing zeroes.

Examples


# Download current OEWS data
oews_data <- get_oews()

# View available occupations
unique(oews_data$occupation_name)

# Filter for specific occupation
software_devs <- oews_data[grepl("Software", occupation_name)]

# Get full diagnostic object if needed
oews_with_diagnostics <- get_oews(return_diagnostics = TRUE)
print_bls_warnings(oews_with_diagnostics)



Download OEWS Area Definitions

Description

Download OEWS Area Definitions

Usage

get_oews_areas(ref_year, silent = TRUE, geometry = TRUE)

Arguments

ref_year

Four-digit year (converted to integer). The year for which to retrieve OEWS area definitions. Valid values are 2024 through current release year. Prior years included Township codes, which change the structure of the file.

silent

Logical. If TRUE (default), suppress console output

geometry

Logical. If TRUE (default), downloads shapefiles for OEWS area definitions using 'tigris::counties()' and 'tigris::shift_geometry()' to render Alaska, Hawaii, and Puerto Rico with a focus on the area of the continental United States.

Value

Data table which maps individual counties to OEWS area definitions.

Examples


 # Get OEWS area definitions without shapefiles and with processing messages.
 test <- get_oews_areas(ref_year = 2024, geometry = FALSE, silent = FALSE)
 



Get QCEW Data Slices

Description

This function pulls data from the BLS QCEW Open Data Access CSV Data Slices. It iterates over specified years and quarters (or annual data) to retrieve industry-specific or area-specific data tables and merges them into a single data.table. Optionally, it joins internal package lookup tables for industry and area descriptions.

Usage

get_qcew(
  period_type = "quarter",
  year_start = NULL,
  year_end = NULL,
  industry_code = NULL,
  area_code = NULL,
  add_lookups = TRUE,
  silently = FALSE
)

Arguments

period_type

Character. Either "quarter" or "year". Defaults to "quarter".

year_start

Numeric. The first year to retrieve data for. Defaults to the year of the date 6 months prior to the current system date.

year_end

Numeric. The last year to retrieve data for. Defaults to the year of the date 6 months prior to the current system date.

industry_code

Character. The NAICS industry code (e.g., "10", "31-33"). Constructs a URL for an Industry Data Slice. Mutually exclusive with 'area_code'.

area_code

Character. The QCEW area code (e.g., "US000", "32000", "C2982"). Constructs a URL for an Area Data Slice. Mutually exclusive with 'industry_code'.

add_lookups

Logical. If TRUE, joins the package's ind_lookup and area_lookup tables to the results to provide descriptive labels. Defaults to TRUE.

silently

Logical. If TRUE, suppresses status messages about the URLs being accessed. Defaults to FALSE.

Value

A combined data.table containing the requested QCEW data, optionally merged with lookup columns and a calculated date column. The data layout is different for quarterly or annual data files set by the 'period_type' argument.

For Quarterly files:

For Annual files:

Examples


# Get quarterly data for "Total, all industries" (Code 10)
# Includes industry/area descriptions and a date column by default
dt_default <- get_qcew(industry_code = "10")

# Get annual data for Nevada (Code 32000) for 2023 without lookups or messages
dt_year <- get_qcew(period_type = "year",
                    year_start = 2023,
                    year_end = 2023,
                    area_code = "32000",
                    add_lookups = FALSE,
                    silently = TRUE)


Download State Alternative Labor Market Measures (SALT) Data

Description

This function downloads detailed alternative unemployment measures data from BLS, including U-1 through U-6 measures. The data provides a more comprehensive view of labor market conditions beyond the standard unemployment rate (U-3).

Usage

get_salt(
  only_states = TRUE,
  geometry = FALSE,
  suppress_warnings = TRUE,
  return_diagnostics = FALSE
)

Arguments

only_states

Logical. If TRUE (default), includes only state-level data. If FALSE, includes sub-state areas like New York City where available.

geometry

Logical. If TRUE, uses tigris::states() to download shapefiles for the states to include in the data. If FALSE (default), only returns data table.

suppress_warnings

Logical. If TRUE (default), suppress individual download warnings and diagnostic messages for cleaner output during batch processing. If FALSE, returns the data and prints warnings and messages to the console.

return_diagnostics

Logical. If TRUE, returns a bls_data_collection object with full diagnostics. If FALSE (default), returns just the data table.

Value

By default, returns a data.table with Alternative Measures of Labor Underutilization data. If return_diagnostics = TRUE, returns a bls_data_collection object containing data and comprehensive diagnostics. The function also adds derived measures and quartile comparisons across states.

Examples


# Download state-level SALT data
salt_data <- get_salt()

# View top 10 highest U-6 rates by state in current data
latest <- salt_data |> 
  dplyr::filter(date == max(date)) |> 
  dplyr::select(state, u6) |> 
  dplyr::arrange(-u6)
head(latest)

# Include sub-state areas
salt_all <- get_salt(only_states = FALSE)
 
# Download SALT with geometry included
get_salt(geometry = TRUE)

# Get full diagnostic object if needed
data_with_diagnostics <- get_salt(return_diagnostics = TRUE)
print_bls_warnings(data_with_diagnostics)



Check if BLS data object has potential issues with import.

Description

Check if BLS data object has potential issues with import.

Usage

has_bls_issues(bls_obj)

Arguments

bls_obj

A BLS data object

Value

Logical indicating if there were any import issues detected.


NAICS Industry Titles Lookup Table (QCEW)

Description

A data frame containing the structure of the North American Industry Classification System (NAICS) titles and codes used by the U.S. Bureau of Labor Statistics (BLS), including in the Quarterly Census of Employment and Wages (QCEW) program. This data is current as of the 2022 NAICS revision.

This table is primarily used internally by 'BLSloadR' functions to add human-readable industry titles or define valid industry lookups.

Usage

data(ind_lookup)

Format

A data frame with 2678 rows and 7 columns:

Details

The NAICS structure is hierarchical. Codes are typically longer for more detailed industries.

Source

https://www.bls.gov/cew/classifications/industry/industry-titles.htm

Examples

# Load the lookup table
data(ind_lookup)

# Find the industry title for NAICS 51 (Information)
ind_lookup[ind_lookup$industry_code == "51", ]

# Get the supersector codes
supersectors <- ind_lookup[ind_lookup$ind_level == "Supersector", ]

# Get all 3-digit NAICS codes in the Manufacturing industry
mfg_codes <- ind_lookup |> 
dplyr::filter(sector == "31-33" & ind_level == "NAICS 3-digit")

List Available Industry Filters for CES Data

Description

Lists all available industry categories that can be used with the 'industry_filter' parameter in 'get_ces()' function. These filters allow you to download specific industry data instead of the complete dataset.

Usage

list_ces_industries(show_descriptions = FALSE)

Arguments

show_descriptions

Logical. If TRUE, returns a data frame with filter names and descriptions. If FALSE, returns just the filter names.

Value

A character vector of industry filter names, or a data frame with names and descriptions if show_descriptions = TRUE

Examples

# See all available industry filters
list_ces_industries()

# See filters with descriptions
list_ces_industries(show_descriptions = TRUE)

# Use with get_ces
# manufacturing_data <- get_ces(industry_filter = "manufacturing")  # All states

List Available States for CES Data

Description

Lists all available U.S. states and territories that can be used with the 'states' parameter in 'get_ces()' function.

Usage

list_ces_states()

Value

A character vector of available state/territory abbreviations

Examples

# See all available states
list_ces_states()

# Use with get_ces
# ces_data <- get_ces(states = c("MA", "NY"))  # All industries for these states

List Available National CES Dataset Options

Description

This function displays the available dataset filtering options for the get_national_ces() function, helping users understand what specialized datasets are available for download.

Usage

list_national_ces_options(show_descriptions = FALSE)

Arguments

show_descriptions

Logical. If TRUE, shows detailed descriptions of each dataset option. If FALSE (default), shows only the filter names.

Value

A data frame with dataset filter options and their descriptions.

Examples

# Show available dataset filters
list_national_ces_options()

# Show detailed descriptions
list_national_ces_options(show_descriptions = TRUE)


Generic BLS Dataset Download

Description

This function generalizes a method to download all BLS data for a given time series database. These files are accessed from https://download.bls.gov/pub/time.series/ and several datasets are available. A summary of an identified database can be generated using the 'bls_overiew()' function. When multiple potential data files exist (common in large data sets), the function will prompt for an input of which file to use.

Usage

load_bls_dataset(
  database_code,
  return_full = FALSE,
  simplify_table = TRUE,
  suppress_warnings = FALSE,
  which_data = NULL,
  cache = check_bls_cache_env()
)

Arguments

database_code

This is the two digit character identifier for the desired database. Some Valid options are:

  • "ce" - National Current Employment Statistics Data

  • "sm" - State and Metro area Current Employment Statistics Data

  • "mp" - Major Sector Total Factor Productivity

  • "ci" - Employment Cost Index

  • "eb" - Employee Benefits Survey

return_full

This argument defaults to FALSE. If set to TRUE it will return a list of the elements of data retrieved from the BLS separating the data, series, and mapping values downloaded.

simplify_table

This parameter defaults to TRUE. When TRUE it will remove all columns from the date with "_code" in the column name, as well as a series of internal identifiers which provide general information about the series but which are not needed for performing time series analysis. This parameter also converts the column "value" to numeric and generates a date column from the year and period columns in the data.

suppress_warnings

Logical. If TRUE, suppress individual download warnings during processing.

which_data

Character string or NULL. Defaults to NULL.

  • "all" - Automatically selects the data file containing ".1.All" (e.g., "bd.data.1.AllItems" or "le.data.1.AllData").

  • "current" - Automatically selects the data file containing "Current" (e.g., "ce.data.0.Current").

  • NULL - Default behavior. Prompts the user to select a file if multiple exist, or selects the single available file.

If the requested pattern is not found, the function falls back to the default behavior, prompting the user to select a file.

cache

Logical. Uses USE_BLS_CACHE environment variable, or defaults to FALSE. If TRUE, will download a cached file from BLS server and update cache if BLS server indicates an updated file.

Value

This function will return either a bls_data_collection object (if return_full is FALSE or not provided) or a named list of the returned data including the bls_data_collection object.

Examples


# Import All Data
fm_import <- load_bls_dataset("fm", which_data = "all")

# Get $data element
fm_data <- fm_import$data

# Filter to a Series
# Families with Children Under 6 and No Employed Parent

u6_no_emp <- fm_data |> 
  dplyr::filter(series_title == "Total families with children under 6 - with no parent employed") |> 
  dplyr:: select(year, value, fchld_text, fhlf_text, tdat_text)


head(u6_no_emp)


## Not run: 
# Examples requiring manual intervention in the console
# Download Employer Cost Index Data
cost_index <- load_bls_dataset("ci")

# Download separated data, series, and mapping columns
benefits <- load_bls_dataset("eb", return_full = TRUE)

# Download data without removing excess columns and value conversions
productivity <- load_bls_dataset("mp", simplify_table = FALSE)

# Check for download issues
if (has_bls_issues(cost_index)) {
  print_bls_warnings(cost_index, detailed = TRUE)
}


## End(Not run)

Description

Print warnings for BLS data object

Usage

print_bls_warnings(bls_obj, detailed = FALSE, silent = FALSE)

Arguments

bls_obj

A bls_data_collection object

detailed

Logical. If TRUE, shows detailed diagnostics for each file

silent

Logical. If TRUE, suppress console output

Value

Character vector of warnings (invisibly)


Read Plain Text Files from BLS Website

Description

Downloads and reads plain text files from the Bureau of Labor Statistics (BLS) website. This is a companion function to fread_bls() that handles text files rather than structured data tables. The function uses custom headers to ensure reliable access to BLS resources.

Usage

read_bls_text(url)

Arguments

url

A character string specifying the full URL to a text file on the BLS website (e.g., https://download.bls.gov/pub/time.series/).

Details

This function is designed to read descriptive text files from BLS, such as README files or database overview documents. It sends an HTTP GET request with browser-like headers to ensure compatibility with BLS server requirements.

The function will stop with an error if the HTTP request fails (e.g., if the URL is invalid or the server is unavailable).

Value

A character vector where each element is one line from the text file. Lines are split on newline characters (\n).

See Also

bls_overview for formatted database overviews, load_bls_dataset for loading complete datasets

Examples


# Read the overview file for Current Employment Statistics
ces_overview <- read_bls_text(
  "https://download.bls.gov/pub/time.series/ce/ce.txt"
)

# Display the first few lines
head(ces_overview)



Show CES Data Filtering Options

Description

Displays a comprehensive overview of all filtering options available for the 'get_ces()' function, including states, industries, and usage examples.

Usage

show_ces_options()

Examples

# See all filtering options
show_ces_options()

Show National CES Dataset Options and Usage Examples

Description

This function provides a comprehensive overview of the national CES dataset filtering options available in get_national_ces(), including examples of how to use each option.

Usage

show_national_ces_options()

Value

Prints formatted information to the console.

Examples

show_national_ces_options()


Check and Download BLS File with Local Caching

Description

This function manages the downloading of files from the BLS server with a local caching layer. It uses HTTP HEAD requests to compare the server's 'Content-Length' and 'Last-Modified' headers with local file attributes. The file is only downloaded if it does not exist locally, or if the remote version is newer or a different size.

Usage

smart_bls_download(url, cache_dir = NULL, verbose = FALSE)

Arguments

url

A character string representing the URL of the BLS file (e.g., a '.txt' or '.gz' file from download.bls.gov).

cache_dir

A character string specifying the local directory to store cached files. May also be set with the enviroment variable 'BLS_CACHE_DIR' Defaults to a persistent user data directory managed by tools::R_user_dir.

verbose

Logical. Defaults to FALSE. If TRUE, returns status messages for download.

Details

The function uses a specific set of browser-like headers to ensure compatibility with BLS server security policies. Upon a successful download, the local file's modification time is synchronized with the server's 'Last-Modified' header using Sys.setFileTime to ensure accurate future comparisons.

Value

A character string containing the local path to the downloaded (or cached) file.

Examples

## Not run: 
url <- "https://download.bls.gov/pub/time.series/ce/ce.data.0.AllCESSeries"
local_path <- smart_bls_download(url)
data <- data.table::fread(local_path)

## End(Not run)