R/hcd_daily.R

Defines functions `hcd_daily`

#' @title Download daily Historical Climate Data records
#'
#' @description Daily Historical Climate Data for stated station IDs are downloaded from the Government of Canada's Historical Climate Data website.
#' @param station Character or numeric; one or more HCD station IDs.
#' @param year numeric; vector of one or more years
#' @param collapse Logical; if \code{TRUE} and multiple \code{station}s are requested a single \code{data frame} is returned, formed by row-binding the data for each station and prepending a station identifier variable.
#' @param progress Logical; if \code{TRUE}, a bar is shown indicating progress in downloading station data from the HCD website.
#' @param ... Further arguments passed to \code{\link{read_hcd}}.
#'
#' @return A \code{\link{tbl_df}} containing the requested monthly climate data
#'
#' @author Gavin L. Simpson
#'
#' @export
`hcd_daily` <- function(station, year, collapse = TRUE, progress = TRUE, ...) {
    ## Generate URLs
    urls <- hcd_url(station, timescale = "daily", year = year)
    ## Download data
    sdata <- process_downloads(urls$url, progress = progress, ...)
    ## collapse multiple stations to a single tbl_df
    if (collapse) {
        sdata <- collapse_hcd(sdata)
    }
    sdata
}
gavinsimpson/canadaHCD documentation built on Sept. 23, 2023, 3:13 a.m.