The data is cached for the duration of the current R session. Series are retrieved in batches in a single request each, rather than one request per series.
Usage
get_boc_series(
series,
start_date = NULL,
end_date = NULL,
recent = NULL,
recent_weeks = NULL,
recent_months = NULL,
recent_years = NULL,
order_dir = NULL,
quarter_convention = getOption("canbank.quarter_convention", "middle"),
quiet = FALSE,
refresh = FALSE
)Arguments
- series
A vector of series identifiers
- start_date
(Optional) Start date for time series
- end_date
(Optional) End date for time series
- recent
(Optional) Only retrieve most recent
recentnumber of data points- recent_weeks
(Optional) Only retrieve data for most recent
recent_weeksweeks- recent_months
(Optional) Only retrieve data for most recent
recent_monthsmonths- recent_years
(Optional) Only retrieve data for most recent
recent_yearsyears- order_dir
(Optional) Order observations by dimension, either
"asc"or"desc"- quarter_convention
(Optional) Which day to use for observations the API reports as a quarter rather than a date, for example
"1998Q3". One of"middle"(the default, mapping Q1 to February 1, Q2 to May 1, Q3 to August 1 and Q4 to November 1),"start"(the first day of the quarter) or"end"(the last day of the quarter). Observations the API reports as a date are used as reported and are unaffected by this. Defaults togetOption("canbank.quarter_convention", "middle").- quiet
(Optional) Don't emit messages or warnings if
TRUE, default isFALSE- refresh
(Optional) Refresh currently cached series if
TRUE, default isFALSE
Value
a tibble with series data. value holds the observation as the
API reports it and Value its numeric coercion; Value is
omitted when no observation in the result is numeric, as for the auction
series that hold ISINs, maturity codes or clock times. NULL if the
API could not be reached.
Details
Returns NULL, with a warning, if the Bank of Canada API cannot be
reached or refuses the request.
Examples
# \donttest{
# daily US dollar and euro exchange rates for the past week
get_boc_series(c("FXUSDCAD", "FXEURCAD"), recent_weeks = 1)
#> Downloading BOC series data for FXUSDCAD, FXEURCAD
#> # A tibble: 10 × 8
#> dimension dimension_value Date series label description value Value
#> <chr> <chr> <date> <chr> <chr> <chr> <chr> <dbl>
#> 1 Date 2026-08-17 2026-08-17 FXEURCAD EUR/CAD Daily aver… 1.60… 1.61
#> 2 Date 2026-08-17 2026-08-17 FXUSDCAD USD/CAD Daily aver… 1.38… 1.39
#> 3 Date 2026-08-18 2026-08-18 FXEURCAD EUR/CAD Daily aver… 1.60… 1.61
#> 4 Date 2026-08-18 2026-08-18 FXUSDCAD USD/CAD Daily aver… 1.38… 1.39
#> 5 Date 2026-08-19 2026-08-19 FXEURCAD EUR/CAD Daily aver… 1.61… 1.61
#> 6 Date 2026-08-19 2026-08-19 FXUSDCAD USD/CAD Daily aver… 1.38… 1.38
#> 7 Date 2026-08-20 2026-08-20 FXEURCAD EUR/CAD Daily aver… 1.60… 1.61
#> 8 Date 2026-08-20 2026-08-20 FXUSDCAD USD/CAD Daily aver… 1.37… 1.38
#> 9 Date 2026-08-21 2026-08-21 FXEURCAD EUR/CAD Daily aver… 1.60… 1.61
#> 10 Date 2026-08-21 2026-08-21 FXUSDCAD USD/CAD Daily aver… 1.37… 1.38
# }