#' Retrieves the month and year of accidents for given years.
#'
#' @param years A nuemric vector of years
#'
#' @return Returns a data frame of month/year columns of accidents for each year as an item in a list
#'
#' @importFrom dplyr mutate
#' @importFrom dplyr select
#' @importFrom magrittr "%>%"
#'
#' @note Returns a warning if the file does not exist. Remeber to set an appropriate working directory.
#'
#' @examples fars_read_years(2013)
#' @examples fars_read_years(2013:2015)
#'
#' @export
fars_read_years <- function(years) {
lapply(years, function(year) {
file <- make_filename(year)
tryCatch({
dat <- fars_read(file)
dplyr::mutate(dat, year = year) %>%
dplyr::select(MONTH, year)
}, error = function(e) {
warning("invalid year: ", year)
return(NULL)
})
})
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.