Skip to contents

Validates bls_url and email as string scalars, verifies the email format, sends a GET request using httr2 with the email in the User-Agent header and a request timeout, and on a successful response with Content-Type: text/plain or text/tab-separated-values and a non-empty body, parses the payload as TSV via readr and returns a tibble.

Usage

get_bls_data(bls_url, email)

Arguments

bls_url

A string scalar BLS URL (e.g., "https://download.bls.gov/pub/time.series/jt/jt.data.1.AllItems").

email

A string scalar email address to include in the User-Agent header.

Value

A tibble parsed from the TSV response body.

Details

  • Email validation uses a practical regex rather than full RFC 5322.

  • HTTP errors (non-2xx) raise an error with status, reason, URL, response headers, and a short body snippet (best-effort).

  • If the response is successful but not text/plain or text/tab-separated-values, or the body is empty, an error is raised (with headers included).

Examples

if (FALSE) { # \dontrun{
df <- get_bls_data(
  bls_url = "https://download.bls.gov/pub/time.series/jt/jt.data.1.AllItems",
  email   = "you@example.com"
)
} # }