| Title: | Access International Monetary Fund Data via the 'SDMX' 3.0 API |
|---|---|
| Description: | Download macroeconomic and financial statistics from the International Monetary Fund data portal (<https://data.imf.org>), served through an 'SDMX' 3.0 REST API. Provides a tidy interface to the Fund's flagship databases, beginning with the World Economic Outlook, and reads the compact 'SDMX-CSV' representation of each query for fast, dependency-light parsing. |
| Authors: | Charles Coverdale [aut, cre] |
| Maintainer: | Charles Coverdale <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-06-16 12:31:06 UTC |
| Source: | https://github.com/charlescoverdale/readimf |
Download a codelist (the valid codes and labels for a dimension), for example the country list or an indicator list, as a tidy data frame.
imf_codelist(id, agency = "IMF", version = "+")imf_codelist(id, agency = "IMF", version = "+")
id |
Codelist id, for example |
agency |
Owning agency. Most shared codelists are |
version |
Codelist version; |
A data frame with columns code and label.
imf_codelist("CL_WEO_INDICATOR", agency = "IMF.RES")imf_codelist("CL_WEO_INDICATOR", agency = "IMF.RES")
The share, or nominal value, of a reserve currency in allocated world foreign
exchange reserves, from the IMF COFER data flow. COFER is published only
for world and country-group aggregates, never individual economies.
imf_cofer( currency = "USD", measure = c("share", "value"), group = "G001", freq = "Q", start = NULL, end = NULL )imf_cofer( currency = "USD", measure = c("share", "value"), group = "G001", freq = "Q", start = NULL, end = NULL )
currency |
Reserve currency code: |
measure |
|
group |
Aggregate code; |
freq |
Frequency code ( |
start, end
|
Optional first and last year to keep. |
An object of class imf_tbl (a data frame).
# US dollar share of world allocated reserves imf_cofer(currency = "USD", measure = "share")# US dollar share of world allocated reserves imf_cofer(currency = "USD", measure = "share")
Commodity price levels or indices, from the IMF PCPS data flow (Primary
Commodity Price System). Prices are global, so no country is required.
imf_commodity( indicator = "PALLFNF", measure = c("index", "usd", "pch_year", "pch"), freq = "M", start = NULL, end = NULL )imf_commodity( indicator = "PALLFNF", measure = c("index", "usd", "pch_year", "pch"), freq = "M", start = NULL, end = NULL )
indicator |
A PCPS commodity code, for example |
measure |
|
freq |
Frequency code ( |
start, end
|
Optional first and last year to keep. |
An object of class imf_tbl (a data frame).
imf_commodity("POILWTI", measure = "usd", start = 2015) imf_commodity("PALLFNF", measure = "index")imf_commodity("POILWTI", measure = "usd", start = 2015) imf_commodity("PALLFNF", measure = "index")
Convenience wrapper returning the master country and area codelist (ISO 3-letter codes and names).
imf_countries()imf_countries()
A data frame with columns code and label.
imf_countries()imf_countries()
Consumer price index or year-on-year inflation, from the IMF CPI data flow.
imf_cpi( country, measure = c("index", "inflation"), freq = "M", start = NULL, end = NULL )imf_cpi( country, measure = c("index", "inflation"), freq = "M", start = NULL, end = NULL )
country |
Character vector of ISO 3-letter country codes. Required. |
measure |
|
freq |
Frequency code ( |
start, end
|
Optional first and last year to keep. |
An object of class imf_tbl (a data frame).
imf_cpi("GBR", measure = "inflation", start = 2015)imf_cpi("GBR", measure = "inflation", start = 2015)
The general-purpose accessor behind the database-specific wrappers. Supply a
data flow id and a key. Use imf_dimensions() to discover the dimension
order and imf_codelist() to discover valid codes.
imf_data( dataflow, key = NULL, agency = NULL, version = "+", start = NULL, end = NULL )imf_data( dataflow, key = NULL, agency = NULL, version = "+", start = NULL, end = NULL )
dataflow |
Data flow id, for example |
key |
Either a ready-made key string (for example |
agency |
Owning agency. If |
version |
Data flow version; |
start, end
|
Optional first and last year to keep. |
An object of class imf_tbl (a data frame).
imf_data("WEO", "GBR.NGDP_RPCH.A", start = 2015, end = 2024)imf_data("WEO", "GBR.NGDP_RPCH.A", start = 2015, end = 2024)
Return every dataset (data flow) published on the IMF 'SDMX' 3.0 portal:
its id, descriptive name, owning agency and version. The catalogue is
fetched once per session and memoised; pass refresh = TRUE to refetch. If
the API cannot be reached, a snapshot bundled with the package is returned.
imf_dataflows(refresh = FALSE)imf_dataflows(refresh = FALSE)
refresh |
Logical. Refetch from the API instead of using the session-memoised catalogue. |
A data frame with columns id, name, agency and version.
flows <- imf_dataflows() head(flows)flows <- imf_dataflows() head(flows)
Return the ordered dimensions of a data flow's data structure. This is the
order in which values must be supplied when building a key for imf_data().
imf_dimensions(dataflow, agency = NULL)imf_dimensions(dataflow, agency = NULL)
dataflow |
Data flow id, for example |
agency |
Owning agency. If |
A data frame with columns position (zero-based) and dimension.
imf_dimensions("WEO")imf_dimensions("WEO")
Goods exports or imports between a reporter and a partner economy, from the
IMF IMTS data flow (the successor to Direction of Trade Statistics).
imf_dots( reporter, partner, flow = c("exports", "imports"), freq = "M", start = NULL, end = NULL )imf_dots( reporter, partner, flow = c("exports", "imports"), freq = "M", start = NULL, end = NULL )
reporter |
ISO 3-letter code of the reporting economy. Only economies that report to the IMF appear here; many (including the UK) do not. |
partner |
ISO 3-letter code of the partner (counterpart) economy. |
flow |
|
freq |
Frequency code ( |
start, end
|
Optional first and last year to keep. |
An object of class imf_tbl (a data frame).
# US goods exports to the UK imf_dots("USA", "GBR", flow = "exports", start = 2020)# US goods exports to the UK imf_dots("USA", "GBR", flow = "exports", start = 2020)
General government revenue or expenditure, from the IMF GFS_SOO data flow
(Government Finance Statistics, Statement of Operations).
imf_gfs( country, indicator = c("revenue", "expenditure"), measure = c("xdc", "pct_gdp"), sector = "S13", freq = "A", start = NULL, end = NULL )imf_gfs( country, indicator = c("revenue", "expenditure"), measure = c("xdc", "pct_gdp"), sector = "S13", freq = "A", start = NULL, end = NULL )
country |
Character vector of ISO 3-letter country codes. Required. |
indicator |
|
measure |
|
sector |
Institutional sector; |
freq |
Frequency code ( |
start, end
|
Optional first and last year to keep. |
An object of class imf_tbl (a data frame).
imf_gfs("GBR", indicator = "revenue", measure = "pct_gdp")imf_gfs("GBR", indicator = "revenue", measure = "pct_gdp")
International Financial Statistics (IFS) was retired when the IMF moved to
the 'SDMX' 3.0 portal. Its content was split across several thematic data
flows (consumer prices, exchange rates, monetary statistics and others) with
no official code crosswalk, which broke every workflow built on the old IFS
series codes. imf_ifs() accepts a legacy IFS indicator code and routes the
request to the correct new data flow and key.
Use imf_ifs_map() to see which legacy series are supported and where each
one now lives. Country coverage in the new data flows varies, especially for
interest rates; if a country returns nothing, try another.
imf_ifs(indicator, country = NULL, freq = NULL, start = NULL, end = NULL)imf_ifs(indicator, country = NULL, freq = NULL, start = NULL, end = NULL)
indicator |
A legacy IFS indicator code, for example |
country |
Character vector of ISO 3-letter country codes, for example
|
freq |
Frequency code ( |
start, end
|
Optional first and last year to keep. |
An object of class imf_tbl (a data frame). The originating IFS code
is retained in the imf_ifs_code attribute.
# UK consumer price index, the series formerly known as IFS PCPI_IX imf_ifs("PCPI_IX", country = "GBR", start = 2015)# UK consumer price index, the series formerly known as IFS PCPI_IX imf_ifs("PCPI_IX", country = "GBR", start = 2015)
Reveal which new data flow and key each supported legacy IFS indicator maps
to. This is the documentation behind imf_ifs() and a migration aid in its
own right: it shows where a retired IFS series now lives without fetching any
data.
imf_ifs_map(indicator = NULL)imf_ifs_map(indicator = NULL)
indicator |
Optional vector of legacy IFS codes to filter to. With no argument the whole crosswalk is returned. |
A data frame with columns ifs_code, description, agency,
dataflow, key_template and default_freq.
imf_ifs_map() imf_ifs_map("PCPI_IX")imf_ifs_map() imf_ifs_map("PCPI_IX")
Case-insensitive search over data flow ids and names.
imf_search(pattern)imf_search(pattern)
pattern |
Regular expression or plain text to match. |
A data frame: the matching rows of imf_dataflows().
imf_search("consumer price") imf_search("balance of payments")imf_search("consumer price") imf_search("balance of payments")
Fetch series from the IMF World Economic Outlook (WEO), the Fund's flagship forecast database. The WEO is openly available, so no API key is required.
imf_weo( indicator = NULL, country = NULL, start = NULL, end = NULL, vintage = "latest" )imf_weo( indicator = NULL, country = NULL, start = NULL, end = NULL, vintage = "latest" )
indicator |
Character vector of WEO indicator codes, for example
|
country |
Character vector of ISO 3-letter country codes, for example
|
start, end
|
Optional first and last year to keep, for example |
vintage |
Either |
An object of class imf_tbl (a data frame) with columns country,
indicator, freq, period and value, carrying provenance attributes.
imf_weo("NGDP_RPCH", country = c("GBR", "USA"), start = 2015, end = 2024)imf_weo("NGDP_RPCH", country = c("GBR", "USA"), start = 2015, end = 2024)
Print an IMF data table
## S3 method for class 'imf_tbl' print(x, n = 10L, ...)## S3 method for class 'imf_tbl' print(x, n = 10L, ...)
x |
An |
n |
Number of rows to print. |
... |
Unused, for S3 compatibility. |
x, invisibly.