MyNixOS website logo
Description

Make Requests from the Bureau of Labor Statistics API.

Implements v2 of the B.L.S. API for requests of survey information and time series data through 3-tiered API that allows users to interact with the raw API directly, create queries through a functional interface, and re-shape the data structures returned to fit common uses. The API definition is located at: <https://www.bls.gov/developers/api_signature_v2.htm>.

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
Metadata

Version

0.5.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows