#' Download bond yields from Bank of Canada website.
#'
#' @param years_span A positive integer
#'
#' @return bondyields_bofc Data.frame of bond yields for the last \code{years_span} years
#'
#' @examples
#' # For the last year of data
#' download_bondyields(1)
#'
#' # For the last 10 years of data
#' download_bondyields(10)
#'
download_bondyields <- function( years_span = 10 ){
# Get url query string to grab data
query_str <- create_bonds_query_string( years_span = years_span )
# Download dataset
temp <- tempfile( )
download.file( query_str, temp, mode = "wb", quiet = TRUE )
# Read in dataset and clean up
bondyields_bofc <- read.csv( temp, header = FALSE, stringsAsFactors = FALSE, skip = 23 )
# create column names
new_colnames <- c( "dates", "MONTH24", "MONTH36", "MONTH60", "MONTH84", "MONTH120", "MONTH360" )
names( bondyields_bofc ) <- new_colnames
# Update dataset and return it
unlink( temp )
return( bondyields_bofc )
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.