imf.data

Package Version R-CMD-check downloads

imf.data provides an R interface to the IMF SDMX 3.0 API. It supports discovering datasets, inspecting their dimensions, and downloading observations as tidy data frames. Raw SDMX responses are also available for advanced use.

Installation

Install imf.data from CRAN:

install.packages("imf.data")

Install the development version from GitHub:

pak::pak("pedrobtz/imf.data")

Quick start

library(imf.data)

# Discover IMF Statistics Department datasets
datasets <- list_datasets("IMF.STA")
datasets[datasets$id == "CPI", ]
# Inspect a dataset's key dimensions
list_dimensions("CPI")
# Find valid frequency codes for US CPI data
list_dimension_values(
  "CPI",
  "FREQUENCY",
  filters = list(COUNTRY = "USA")
)
# Download the latest monthly headline CPI observations
cpi <- get_data(
  "CPI",
  filters = list(
    COUNTRY = c("USA", "CAN"),
    INDEX_TYPE = "CPI",
    COICOP_1999 = "_T",
    TYPE_OF_TRANSFORMATION = "IX",
    FREQUENCY = "M"
  ),
  last_n_obs = 12,
  attributes = "STATUS"
)
cpi

get_data() returns one row per observation. Dimension and time columns are character vectors, OBS_VALUE is numeric, and requested SDMX attributes are included as additional columns.

Raw SDMX access

raw <- sdmx_data(
  "CPI",
  key = "USA.CPI._T.IX.M",
  last_n_obs = 2
)

See vignette("getting-started") for a complete workflow.

Proxy configuration

httr2 respects standard proxy environment variables such as HTTPS_PROXY and NO_PROXY. A proxy can also be configured specifically for imf.data:

set_imf_proxy(
  "http://proxy.example.com",
  port = 8080,
  username = Sys.getenv("PROXY_USER"),
  password = Sys.getenv("PROXY_PASSWORD")
)

list_datasets("IMF.STA")
clear_imf_proxy()

The package-specific configuration applies to all raw and tidy API functions for the remainder of the R session, until clear_imf_proxy() is called.