The BIS
package provides an R
interface to data hosted by the Bank for International Settlements, specifically the single-file data sets available on the BIS homepage.
You can install the package from CRAN or GitHub.
library(devtools) install_github("stefanangrick/BIS") # GitHub install.packages("BIS") # CRAN
To start using the package, load it into your R session.
library("BIS")
Next, retrieve a list of available data sets using the get_datasets()
function.
ds <- get_datasets() head(ds, 20)
The get_datasets()
function returns a tibble data frame listing available data sets. Use the url
column as input for the get_bis()
function to download, parse, and import the corresponding data set.
For example, to import monthly-frequency data on central banks' policy rates, use the following code:
rates <- get_bis(ds$url[ds$id == "WS_CBPOL_csv_flat"]) head(rates)
To plot the data with ggplot2, run the following:
library("dplyr") library("ggplot2") library("zoo") rates_plot <- subset(rates, ref_area %in% c("US", "XM", "JP", "GB", "CH", "CA")) rates_plot <- subset(rates, ref_area %in% c("US: United States", "XM: Euro area", "JP: Japan", "GB: United Kingdom", "CH: Switzerland", "CA: Canada")) rates_plot <- mutate(rates_plot, time_period = as.Date(as.yearmon(time_period, format = "%Y-%m"))) ggplot(rates_plot, aes(time_period, obs_value, color = ref_area)) + geom_line(show.legend = FALSE) + facet_wrap(~ref_area) + labs(title = "Central bank policy rates", subtitle = "% per annum", x = NULL, y = NULL)
Note that BIS data sets use various time formats. The zoo package (e.g., as.yearmon()
) can handle most of these formats.
In some cases, the BIS homepage may only be accessible through a web browser, preventing the programmatic retrieval of data sets directly within R. When this occurs, users can manually download the files and use the read_bis()
function to parse them.
To read a locally stored CSV file, use the following code:
df <- read_bis("WS_CBPOL_csv_flat.csv")
To read a locally stored ZIP file, use this code:
df <- read_bis(.unzip_file("WS_CBPOL_csv_flat.zip"))
To retrieve individual data series instead of full data sets, consider using the BIS SDMX RESTful API. The rsdmx R package supports processing SDMX data in R. The latest development version of rsdmx
includes a BIS connector to streamline the process.
This package is neither officially related to nor endorsed by the Bank for International Settlements. It is based on a fork of CC0-licensed code by expersso. Please avoid overloading the BIS servers with unnecessary requests.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.