#' Get fund data.
#'
#' \code{getFundData} loads the fund data from the specified directory and file.
#' If the file does not exist, then it downloads the data and stores it in the
#' specified file.
#'
#' @export
#'
#' @param file String, file name. Default is generated based on today's date.
#' @param dir String, directory of the file. Default is generated temporary
#' directory.
#' @param force Logical, whether to force download data even if the file with
#' the specified name already exists.
#' @param quite Logical, whether to suppress any output to console.
#'
#' @return Data frame, with the fund data.
#'
#' @source Data comes from \url{http://manapensija.lv}.
#'
#' @seealso \code{\link{downloadFundData}}.
getFundData <- function(file = paste0("fund-data-", Sys.Date(), ".RData"),
dir = tempdir(),
force = FALSE,
quite = FALSE) {
filePath <- paste(dir, file, sep = "/")
if (!file.exists(filePath)){
if (!quite) {
cat("File not found. Downloading data into ", filePath, "\n")
}
downloadFundData(file, dir)
if (!quite) {
cat("Data saved into", filePath, "\n")
}
} else if (force) {
if (!quite) {
cat("Force downloading data into.", filePath, "\n")
}
downloadFundData(file, dir)
if (!quite) {
cat("Data saved into", filePath, "\n")
}
}
if (!quite) {
cat("File", filePath, "exists. Loading.\n")
}
load(filePath)
if (!quite) {
cat("Loaded.\n")
}
load(filePath)
return(fundData)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.