bls-api-key {blsR}R Documentation

Managing API keys

Description

It is strongly recommended users of the BLS API use an API key. This key can be stored as environment variable, BLS_API_KEY.

Usage

bls_set_key(key)

bls_unset_key()

bls_get_key()

bls_has_key()

Arguments

key

A valid BLS API key as a string. keys are typically 32 characters in length and a key with a different length will trigger a warning.

Registering for and using an API key

Registering for an API key is not required to use the BLS API, but it is recommended you register for an API key and use it. Requests without a key are limited to 10 years of data per request, 25 series per query, and 25 queries per day. You can register for an API key at: https://data.bls.gov/registrationEngine/

Persistence

The preferred method to set the key is to set the BLS_API_KEY environment variable in an .Renviron file. The easiest way to do this is by calling usethis::edit_r_environ(). Don't forget to restart R after setting the key.

See Also

Other blsR-utils: data_as_table(), data_as_tidy_table(), merge_tables(), merge_tidy_tables(), reduce_spanned_responses(), span_request_queries(), span_series_request(), tidy_periods(), tidy_table_as_zoo()

Other blsR-utils: data_as_table(), data_as_tidy_table(), merge_tables(), merge_tidy_tables(), reduce_spanned_responses(), span_request_queries(), span_series_request(), tidy_periods(), tidy_table_as_zoo()

Other blsR-utils: data_as_table(), data_as_tidy_table(), merge_tables(), merge_tidy_tables(), reduce_spanned_responses(), span_request_queries(), span_series_request(), tidy_periods(), tidy_table_as_zoo()

Other blsR-utils: data_as_table(), data_as_tidy_table(), merge_tables(), merge_tidy_tables(), reduce_spanned_responses(), span_request_queries(), span_series_request(), tidy_periods(), tidy_table_as_zoo()

Examples


has_key <- bls_has_key()

if(has_key){
  original_key <- bls_get_key()
  bls_unset_key()
}

#no initial key
bls_has_key()

# Set a session key
bls_set_key("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")

bls_has_key()

# Get session key
bls_get_key()

# Reset to original key
if(has_key) bls_set_key(original_key)

[Package blsR version 0.5.0 Index]