knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

valet

This package provides an R client to the Bank of Canada's valet API. It provide access to all of the API's functionality except its RSS feeds. There are currently a few bugs in how it handles series groups, and some tests to develop and run.

installation

You can install the development version of valet from GitHub with:

install.packages("devtools")
devtools::install_github("runkelcorey/valet")

basic usage

The core functions of valet are get_series() and get_group(). These retrieve observations from series and series groups, subject to some date filters. Here's an example of the last five Canadian dollar--US dollar exchange-rate observations.

library(valet)
get_series("FXCADUSD", recent = 5)

workflow

  1. Suppose a researcher wanted to see what datasets the Bank of Canada offered:
datasets <- get_list("groups")

This can be overwhelming, but it does allow us to filter. Let's look for monthly Canadian Effective Exchange Rates:

subset(datasets, grepl("CEER", label))

We have two potential datasets, and the option to choose real or nominal data. Let's take a look at their details before we grab what could be thousands of observations (in this case, let's say we're more interested in their comparisons against non-US major currencies than that they be nominal or real):^[It's important to note that get_details and valet make a distinction between grouped observations and single series. The user must select group = TRUE or valet will not return a dataset.]

get_details("CEER_MONTHLY_REAL", group = T)
get_details("CEER_MONTHLY_NOMINAL", group = T)

Both datasets satisfy this condition, so we'll grab the real data.

  1. Download selected data
get_group("CEER_MONTHLY_REAL")
  1. You can grab a bunch of observations with a map-reduce framework, or leverage the Bank of Canada's own, comma-separated querying feature:
get_list("series") %>%
  subset(grepl("NOON", label)) %>%
  .$name %>%
  paste0(collapse = ",") %>%
  get_series()

also

The Bank of Canada's API documentation explains API usage thoroughly. Their website is useful for finding series too.



runkelcorey/valet documentation built on June 1, 2025, 4:01 p.m.