Learn R Programming

blsR

The goal of blsR is to make it easy to request time series data from the BLS API and turn it into usable tabular data.

Installation

You can install the released version of blsR from CRAN with:

install.packages("blsR")

And the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("groditi/blsR")

Getting Started

blsR provides functions for retrieving and processing data from the BLS API. The functions are divided into 4 categories: query generators, query requests, result processors, and the user-friendly simplified interface. It was designed with a three-step workflow in mind:

  • Identify which data you would like to retrieve and create a query.
  • Make an http request to execute a query ([bls_request()])
  • Transform the response data to fit the user workflow

If the only data needed is periods and values, then the functions get_series_table, get_series_tables, and get_n_series_table are all that a user will need. An API key is not required to use this package but users will be restricted in how many years of data can be retrieved per request, how many series can be included per request, and how many requests can be made in a day. An API Key can be obtained at: https://data.bls.gov/registrationEngine/ ## Example

This is a basic example which shows you how to retrieve one series as a tibble or retrieve two series as a joined tibble.

Example

To request a single series as a tibble:

library(blsR)
uer <- get_series_table('LNS14000000', start_year = 2006, end_year = 2006)

# uer: 
# # A tibble: 12 x 5
#    year  period periodName value footnotes       
#    <chr> <chr>  <chr>      <chr> <list>          
#  1 2006  M12    December   4.4   <named list [0]>
#  2 2006  M11    November   4.5   <named list [0]>
#  3 2006  M10    October    4.4   <named list [0]>
#  4 2006  M09    September  4.5   <named list [0]>
#  5 2006  M08    August     4.7   <named list [0]>
#  6 2006  M07    July       4.7   <named list [0]>
#  7 2006  M06    June       4.6   <named list [0]>
#  8 2006  M05    May        4.6   <named list [0]>
#  9 2006  M04    April      4.7   <named list [0]>
# 10 2006  M03    March      4.7   <named list [0]>
# 11 2006  M02    February   4.8   <named list [0]>
# 12 2006  M01    January    4.7   <named list [0]>

tidy_periods(uer)
# # A tibble: 12 x 4
#     year month value footnotes       
#    <int> <int> <chr> <list>          
#  1  2006     1 4.7   <named list [0]>
#  2  2006     2 4.8   <named list [0]>
#  3  2006     3 4.7   <named list [0]>
#  4  2006     4 4.7   <named list [0]>
#  5  2006     5 4.6   <named list [0]>
#  6  2006     6 4.6   <named list [0]>
#  7  2006     7 4.7   <named list [0]>
#  8  2006     8 4.7   <named list [0]>
#  9  2006     9 4.5   <named list [0]>
# 10  2006    10 4.4   <named list [0]>
# 11  2006    11 4.5   <named list [0]>

To request multiple series as one tibble

get_n_series_table(
  list('LNS14000001', 'LNS14000002'), start_year = 2005, end_year=2006
  )
# # A tibble: 24 x 4
#     year period LNS14000001 LNS14000002
#    <int> <chr>  <chr>       <chr>      
#  1  2006 M12    4.5         4.4        
#  2  2006 M11    4.5         4.5        
#  3  2006 M10    4.4         4.4        
#  4  2006 M09    4.4         4.7        
#  5  2006 M08    4.7         4.6        
#  6  2006 M07    4.7         4.7        
#  7  2006 M06    4.6         4.6        
#  8  2006 M05    4.7         4.5        
#  9  2006 M04    4.7         4.7        
# 10  2006 M03    4.7         4.7        
# # ... with 14 more rows

get_n_series_table(
  list(uer.men ='LNS14000001', uer.women = 'LNS14000002'),
  start_year = 2005, end_year=2006, tidy=TRUE
)

# # A tibble: 24 x 4
#     year month uer.men uer.women
#    <int> <int> <chr>   <chr>    
#  1  2005     1 5.4     5.1      
#  2  2005     2 5.5     5.3      
#  3  2005     3 5.3     5.1      
#  4  2005     4 5.1     5.2      
#  5  2005     5 5.0     5.2      
#  6  2005     6 5.0     5.1      
#  7  2005     7 4.9     5.1      
#  8  2005     8 4.9     4.9      
#  9  2005     9 5.0     5.1      
# 10  2005    10 4.8     5.1      
# # ... with 14 more rows

Copy Link

Version

Install

install.packages('blsR')

Monthly Downloads

471

Version

0.5.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Guillermo Roditi Dominguez

Last Published

July 5th, 2023

Functions in blsR (0.5.0)

merge_tables

Turn a list of one or more series into a single table of time series data
query_all_surveys

Create a query to retrieve all surveys
query_n_series

Create a query to retrieve one or more time series and their catalog data
query_latest_observation

Create a Query to retrieve the latest observation for a time series
merge_tidy_tables

Turn a list of one or more series into a single table of time series data
query_popular_series

Create a query to retrieve popular series
get_survey_info

Create and execute a query to retrieve information about a survey
get_series

Create and execute query for a single time series
get_series_tables

Retrieve multiple time series as in one API request as tibbles
get_series_table

Retrieve a time series from BLS API as a tibble
reduce_spanned_responses

Reduce the multiple spanned responses into a list of series
tidy_periods

Clean the period information returned by BLS
query_series

Create a query for a single time series
span_series_request

Break up a long request into multiple API calls
query_survey_info

Create a query to retrieve information about a survey
tidy_table_as_zoo

Convert a single series or n series tables into a zoo object
span_request_queries

Generate multiple queries that don't exceed a year limit
get_n_series_table

Retrieve multiple time series in one API request and return a single tibble
bls-api-key

Managing API keys
get_all_surveys

Create and execute a query to retrieve all surveys
data_as_table

Convert a list of data entries as returned by BLS API to a table
data_as_tidy_table

Convert a list of data entries as returned by BLS API to a table
bls_request

Retrieve Data From the U.S. Bureau Of Labor Statistics API v2
get_latest_observation

Create and execute a query to retrieve the latest observation for a series
get_n_series

Create and execute a query to retrieve one or more time series and their catalog data
blsR

blsR: Retrieve Data From the U.S. Bureau Of Labor Statistics API
get_popular_series

Create and execute a query to retrieve popular series