CRAN Version Build Status CRAN Monthly Downloads CRAN Total Downloads

R package for interacting with the International Monetary Funds’s RESTful JSON API.

How to download IMF data

You can use the imf_data function to download the data the IMF makes available via its API. To do this you will need at least the following information:


Simple Country-Time-Variable

Imagine that we want to download Effective Exchange Rate (CPI base) for China and the UK for 2013:


real_ex <- imf_data(database_id = 'IFS', indicator = 'EREER_IX',
                    country = c('CN', 'GB'), freq = 'A',
                    start = 2013, end = current_year())
##   iso2c year EREER_IX
## 1    CN 2013 115.2979
## 2    CN 2014 118.9859
## 3    CN 2015 131.6297
## 4    GB 2013 105.7684
## 5    GB 2014 113.7014
## 6    GB 2015 121.7981

More complex data formats

While many quantities of interest from the IMF database are in simple country-time-variable format, many are not. For example, Direction of Trade Statistics include country-year-variable and a “counterpart area”. By default, imf_data would only return the first, but not the last.

Because of the many possible data structures available from the imf, imf_data allows you to return the entire API call as a list. From this list you can then extract the requested data. To do this use the return_raw = TRUE argument, e.g.:

data_list <- imf_data(database_id = "DOT", indicator = "TXG_FOB_USD", 
                      country = "US", return_raw = TRUE)

Then extract the data series (it is typically contained in CompactData$DataSet$Series):

data_df <- data_list$CompactData$DataSet$Series

## [1] "@FREQ"             "@REF_AREA"         "@INDICATOR"       
## [4] "@COUNTERPART_AREA" "@UNIT_MULT"        "@TIME_FORMAT"     
## [7] "Obs"

You can then subset and clean up data_df to suit your purposes.