| Title: | An Interface to IMF (International Monetary Fund) Data |
| Version: | 0.2.0 |
| Description: | Provides low-level access to the International Monetary Fund Statistical Data and Metadata eXchange ('SDMX') 3.0 API, available at https://data.imf.org/, and a concise workflow for discovering datasets, inspecting dimensions, and downloading observations as tidy data frames. |
| Depends: | R (≥ 4.0.0) |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| Imports: | httr2 (≥ 1.0.0), tibble |
| Suggests: | knitr, rmarkdown, testthat (≥ 3.0.0), vcr (≥ 2.0.0) |
| Config/testthat/edition: | 3 |
| VignetteBuilder: | knitr |
| Collate: | 'sdmx_api.R' 'imf_api.R' |
| URL: | https://pedrobtz.github.io/imf.data/ |
| BugReports: | https://github.com/pedrobtz/imf.data/issues |
| NeedsCompilation: | no |
| Packaged: | 2026-07-06 05:31:22 UTC; pbtz |
| Author: | Pedro Baltazar [aut, cre, cph] |
| Maintainer: | Pedro Baltazar <pedrobtz@gmail.com> |
| Repository: | CRAN |
| Date/Publication: | 2026-07-06 06:10:09 UTC |
Download IMF data as a tidy data frame
Description
Query a dataflow with named dimension filters and decode the indexed SDMX response into one row per observation.
Usage
get_data(
dataflow,
filters = list(),
agency_id = "IMF.STA",
version = "+",
start_period = NULL,
end_period = NULL,
first_n_obs = NULL,
last_n_obs = NULL,
attributes = character()
)
Arguments
dataflow |
Dataflow ID. |
filters |
Named list of dimension selections. |
agency_id |
Maintainer ID. |
version |
Dataflow version. |
start_period, end_period |
Optional SDMX period bounds. |
first_n_obs, last_n_obs |
Optional observation limits per series. |
attributes |
Character vector of series or observation attributes to include in the result. |
Value
A tibble containing dimension columns, TIME_PERIOD, OBS_VALUE,
and any requested attributes.
Examples
get_data(
"CPI",
filters = list(
COUNTRY = "USA",
INDEX_TYPE = "CPI",
COICOP_1999 = "_T",
TYPE_OF_TRANSFORMATION = "IX",
FREQUENCY = "M"
),
last_n_obs = 2
)
List IMF datasets
Description
Return the available IMF SDMX dataflows as a stable, tidy catalogue.
Usage
list_datasets(agency_id = "*")
Arguments
agency_id |
Maintainer ID. Use |
Value
A tibble with agency, id, version, name, description,
and dsd_id columns.
Examples
datasets <- list_datasets("IMF.STA")
List available values for a dataset dimension
Description
Use the IMF availability endpoint to return the codes that remain valid for a dimension, optionally constrained by selections for other dimensions.
Usage
list_dimension_values(
dataflow,
dimension,
filters = list(),
agency_id = "IMF.STA",
version = "+"
)
Arguments
dataflow |
Dataflow ID. |
dimension |
Dimension ID. |
filters |
Named list of selections for other dimensions. |
agency_id |
Maintainer ID. |
version |
Dataflow version. |
Value
A tibble with code, name, and description columns.
Examples
list_dimension_values(
"CPI",
"FREQUENCY",
filters = list(COUNTRY = "USA")
)
List the dimensions of an IMF dataset
Description
Resolve a dataflow's data structure and return its dimensions in SDMX key order, including the associated codelist where one is declared.
Usage
list_dimensions(dataflow, agency_id = "IMF.STA", version = "+")
Arguments
dataflow |
Dataflow ID. |
agency_id |
Maintainer ID. |
version |
Dataflow version. |
Value
A tibble describing each dimension and its codelist.
Examples
list_dimensions("CPI")
IMF SDMX 3.0 API
Description
Low-level access to the IMF SDMX 3.0 structure, data, availability, and
metadata endpoints. These functions return the API response without
converting it to a tidy data frame. See get_data() for the higher-level
interface.
Query data availability
Description
Retrieve the available dimension values matching a data query without downloading observations.
Usage
sdmx_availability(
dataflow,
key = "*",
component_id = "*",
agency_id = "IMF.STA",
version = "+",
context = "dataflow",
filters = list(),
mode = c("exact", "available"),
references = "none",
format = c("json", "xml")
)
Arguments
dataflow |
Dataflow ID. |
key |
SDMX series key. Use |
component_id |
Dimension for which availability is requested. |
agency_id |
Maintainer ID. |
version |
Dataflow version. |
context |
Query context. |
filters |
Named list of component filters. |
mode |
Return exact matches or values that remain available. |
references |
Referenced artefacts to include. |
format |
Response format. XML responses are returned as text. |
Value
A nested list for JSON, a character value for XML, or NULL for
an HTTP 204 response.
Examples
sdmx_availability("CPI", component_id = "COUNTRY")
Query statistical data
Description
Retrieve an SDMX data message from the IMF API. This is the raw interface;
use get_data() to obtain a tidy data frame.
Usage
sdmx_data(
dataflow,
key = "*",
agency_id = "IMF.STA",
version = "+",
context = "dataflow",
filters = list(),
start_period = NULL,
end_period = NULL,
first_n_obs = NULL,
last_n_obs = NULL,
updated_after = NULL,
include_history = FALSE,
attributes = "dsd",
measures = "all",
format = c("json", "xml")
)
Arguments
dataflow |
Dataflow ID. |
key |
SDMX series key. Use |
agency_id |
Maintainer ID. |
version |
Dataflow version. |
context |
Query context. |
filters |
Named list of component filters. |
start_period, end_period |
Optional SDMX period bounds. |
first_n_obs, last_n_obs |
Optional positive observation limits. They cannot be used together. |
updated_after |
Optional RFC 3339 timestamp. |
include_history |
Include historical versions. |
attributes |
Attribute detail requested from the API. |
measures |
Measures requested from the API. |
format |
Response format. XML responses are returned as text. |
Value
A nested list for JSON, a character value for XML, or NULL for
an HTTP 204 response.
Examples
sdmx_data(
"CPI",
agency_id = "IMF.STA",
key = "USA.CPI._T.IX.M",
last_n_obs = 2
)
Query metadata reports
Description
Retrieve metadatasets from the IMF SDMX API.
Usage
sdmx_metadata(
provider_id = "*",
metadataset_id = "*",
version = "+",
detail = c("allstubs", "full"),
format = c("json", "xml")
)
Arguments
provider_id |
Metadata provider ID. |
metadataset_id |
Metadataset ID. |
version |
Metadataset version. |
detail |
Metadata detail level. |
format |
Response format. XML responses are returned as text. |
Value
A nested list for JSON, a character value for XML, or NULL for
an HTTP 204 response.
Examples
sdmx_metadata(detail = "allstubs")
Query structural metadata
Description
Retrieve IMF SDMX structural metadata such as dataflows, data structures, codelists, and concept schemes.
Usage
sdmx_structure(
structure_type = "dataflow",
agency_id = "*",
resource_id = "*",
version = "+",
detail = NULL,
references = NULL,
format = c("json", "xml")
)
Arguments
structure_type |
Type of structure to retrieve. |
agency_id |
Maintainer ID. Use |
resource_id |
Resource ID. Use |
version |
Resource version. |
detail |
Optional SDMX detail level. |
references |
Optional referenced artefacts to include. |
format |
Response format. XML responses are returned as text. |
Value
A nested list for JSON, a character value for XML, or NULL for
an HTTP 204 response.
Examples
sdmx_structure("dataflow", agency_id = "IMF.STA", detail = "allstubs")
sdmx_structure("codelist", "IMF", "CL_FREQ")
Configure an HTTP proxy
Description
Configure a proxy for all subsequent IMF API requests in the current R
session. Credentials are kept in package-private session state, passed to
httr2::req_proxy(), and omitted from returned configuration summaries.
Usage
set_imf_proxy(
url,
port = NULL,
username = NULL,
password = NULL,
auth = proxy_auth_methods
)
clear_imf_proxy()
Arguments
url |
Proxy URL, including its scheme and hostname. |
port |
Optional proxy port. |
username, password |
Optional proxy credentials. Supply both or neither. |
auth |
Proxy authentication method supported by |
Details
Standard proxy environment variables such as HTTPS_PROXY, HTTP_PROXY,
and NO_PROXY continue to work when no package-specific proxy is set.
Value
A redacted summary of the previous proxy configuration, invisibly.
Examples
# Not run: requires a reachable proxy server. The example points at a
# placeholder host, so executing it would route a real request through a
# non-existent proxy and fail.
## Not run:
set_imf_proxy(
"http://proxy.example.com",
port = 8080,
username = "proxy_user",
password = "proxy_password"
)
list_datasets("IMF.STA")
clear_imf_proxy()
## End(Not run)