load_bls_data 2: load_bls_data

load_bls_dataR Documentation

load_bls_data

Description

Returns a data frame containing the specified Bureau of Labor Statistics data.

Usage

load_bls_data(
  file_name,
  series_id,
  start_year = NULL,
  end_year = NULL,
  api_key = NULL,
  fresh_start = FALSE
)

Arguments

file_name

character. The path and filename of an R serial data (.RDS) file to use for loading or saving data on disk.

series_id

character. The BLS series ID used to download data.

start_year

numeric. The first (earliest) year for which you want data for the series_id. If NULL, will attempt to pull the earliest available data.

end_year

numeric. The last (most recent) year for which you want data for the series_id. If NULL, will pull the most recent data.

api_key

Your registred BLS API key, or NULL if you do not have a key.

fresh_start

boolean. If true, will delete any existing data file specified by file_name before proceeding to download new data from the specified series.

Details

If the file specified by file_name already exists, the data is loaded from disk and returned. If the file does not exist, the series ID is used to download the data from the BLS. The data is then saved to the file file_name, and returned as a data frame. In addition to the data returned from the BLS's API, a new column date is added, with data class Date, and the data is sorted by date. Both file_name and series_id should be passed as character strings, e.g. file_name = "data/jobs_u.rds", series_id = "CEU0000000001".

Value

A data frame

Examples

  ## Not run: 
  # Get all years of seasonally adjusted position reported by employers ("jobs report")
  # and save to data/employer_jobs_s.rds
  employer_jobs_s_df <- load_bls_data(file_name = "data/employer_jobs_s.rds",
                                      series_id = "CES0000000001")

  # Get the last decade of unadjusted employer-reported position
  library(magrittr); library(lubridate)
  my_start_date <- today() %>% year()
  employer_decade_df <- load_bls_data(file_name = "data/last_decade_u.rds",
                                      series_id = "CEU0000000001",
                                      start_date = my_start_date)
  
## End(Not run)

tomhopper/blscrapeRplus documentation built on Sept. 2, 2023, 12:30 p.m.