R/fars_read_years.R

#'Read year
#'
#' Loads specified data about year and month.
#'
#' @param years an integer value, describing the year of the data set which is needed. The valid years which can be used are:\code{ 2013, 2014 & 2015}.
#'
#'
#' @details This function using the packages: \bold{readr} & \bold{dplyr}.
#'
#' If an invalid year will be supplied to the function then show an warning messege will appear \emph{invalid year: ...} .
#'
#' @return A list containing a representation of the data in the file.
#'
#' @importFrom dplyr mutate select
#' @importFrom magrittr %>%
#'
#' @examples
#' \dontrun{fars_read_years(2013)}
#'
#'@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)
    })
  })
}
AlphaIgor/Test documentation built on May 19, 2019, 10:47 p.m.