Package 'banxicoR'

Title: Download Data from the Bank of Mexico
Description: Accesses observations and metadata from the Bank of Mexico SIE REST API with authenticated requests, typed long-format results, and compatibility adapters for legacy callers.
Authors: Eduardo Flores [aut, cre]
Maintainer: Eduardo Flores <[email protected]>
License: CC0
Version: 0.9.0.9000
Built: 2026-10-15 21:29:31 UTC
Source: https://github.com/eflores89/banxicor

Help Index


Retrieve Banxico observations and metadata

Description

Uses the authenticated SIE REST API. Obtain a token from Banxico and configure BANXICO_TOKEN or use banxico_set_token(). Metadata retrieval is explicit.

Usage

banxico_data(
  series,
  start_date = NULL,
  end_date = NULL,
  token = banxico_get_token(),
  language = "es"
)

banxico_latest(series, token = banxico_get_token(), language = "es")

banxico_metadata(series, token = banxico_get_token(), language = "es")

Arguments

series

Character vector of alphanumeric series identifiers.

start_date, end_date

Inclusive date bounds as scalar Dates or ISO YYYY-MM-DD strings. Two bounds use the range endpoint; a single bound filters full history locally.

token

API token, defaulting to banxico_get_token().

language

API locale: "es" (default) or "en".

Value

banxico_data() and banxico_latest() return a data.frame with provider, series_id, title, period, date (Date), value (double), and value_raw columns. Raw API periods and unavailable observations are retained. Rows follow requested series order and ascending dates within each series. banxico_metadata() returns provider, series_id, title and available raw API metadata fields; unavailable titles are NA. Empty data is typed.

Examples

## Not run: 
# First configure BANXICO_TOKEN locally with your registered token.
x <- banxico_data(c("SF43718", "SF110168"),
  start_date = "2025-01-01", end_date = "2025-12-31")
banxico_latest("SF43718")
banxico_metadata("SF43718")

## End(Not run)

Retrieve the configured Banxico token

Description

Uses the session token configured by banxico_set_token(), falling back to the BANXICO_TOKEN environment variable. Treat the returned value as secret.

Usage

banxico_get_token()

Value

A validated scalar character token.


Configure a Banxico token for this R session

Description

Configure a Banxico token for this R session

Usage

banxico_set_token(token)

Arguments

token

A nonempty character token without whitespace or control characters.

Value

Invisibly returns NULL. The token is stored only in the session environment.


Catalog of some ID's

Description

A dataset containing the id's for some Banxico series.

Usage

BanxicoCatalog

Format

A data frame with 133 rows and 9 variables:

PARENT

Parent or theme of data series

LEVEL_1

Level one category

LEVEL_2

Level two category

LEVEL_3

Level three category

LEVEL_4

Level four category

LEVEL_5

Level five category

LEVEL_6

Level six category

FREQUENCY

Frequency of data (i.e. monthly)

ID

ID to pass to banxico series


Compact legacy observations and metadata

Description

Uses banxico_series() with metadata requested explicitly. Configure BANXICO_TOKEN or use banxico_set_token() before calling without a token.

Usage

compact_banxico_series(
  series,
  token = banxico_get_token(),
  start_date = NULL,
  end_date = NULL,
  language = "es"
)

Arguments

series

A single character series identifier.

token

API token, defaulting to banxico_get_token().

start_date, end_date

Inclusive scalar Date or ISO YYYY-MM-DD bounds.

language

API locale, either "es" or "en".

Value

A data.frame with Dates, an ID-named numeric value column, and IndicatorName, IndicatorId, Units, DataType, Period and Frequency repeated per observation. Unavailable metadata is NA; empty data has zero rows.

Author(s)

Eduardo Flores


Helper functions for banxico series

Description

Retained helpers for historical quarterly labels and IQY metadata text. These helpers do not contact the API.

Usage

banxico_parsetrim(string, trim_begin = TRUE)

banxico_parsemeta(slist, lookfor, exclude = FALSE)

Arguments

string

A single quarterly label such as "Jan-Mar 2015".

trim_begin

Logical; select the quarter's first month when TRUE.

slist

Character vector of legacy metadata lines.

lookfor

Regular expression selecting metadata lines.

exclude

Logical; exclude matching lines when TRUE.

Details

With trim_begin = FALSE, the quarterly helper returns the first day of the quarter's final month, not the quarter's last calendar day. Unrecognized labels warn and return their nonnumeric text.

Value

banxico_parsetrim() returns a Date for recognized labels, otherwise character text. banxico_parsemeta() returns lowercase character values with the text preceding the first colon removed.

Examples

# trimester
string <- "Jan-Mar 2015"
trim <- banxico_parsetrim(string)

Returns data series from Banxico using the SIE REST API

Description

Legacy adapters retain their original column names and argument positions. API access now requires a token: set BANXICO_TOKEN or call banxico_set_token(). For multiple series and raw values use banxico_data().

Usage

banxico_series(
  series,
  metadata = FALSE,
  verbose = FALSE,
  mask = FALSE,
  token = banxico_get_token(),
  start_date = NULL,
  end_date = NULL,
  language = "es"
)

banxico_series2(
  series,
  token = banxico_get_token(),
  metadata = FALSE,
  mask = FALSE,
  start_date = NULL,
  end_date = NULL,
  language = "es"
)

Arguments

series

A single character series identifier.

metadata

Logical; include legacy metadata (or Name in banxico_series2).

verbose

Logical; print a safe observation count after retrieval.

mask

Logical; use Values or Value instead of an ID-named value column.

token

API token, defaulting to banxico_get_token().

start_date, end_date

Inclusive scalar Date or ISO YYYY-MM-DD bounds.

language

API locale, either "es" or "en".

Value

banxico_series returns Dates and an ID-named numeric column (Values when masked), or a list with MetaData and Data. MetaData contains IndicatorName, IndicatorId, Units, DataType, Period and Frequency; fields unavailable from the API are NA. banxico_series2 returns Date and an ID-named numeric column (Value when masked), plus Name if requested. Missing observations remain rows with NA values.

Author(s)

Eduardo Flores