R/ep_download.R

Defines functions ep_download

Documented in ep_download

#' Downloads air pollution data for European cities
#'
#' @param country A string. Country ISO code
#' @param cities A string vector. Contains the names of cities desired
#' @param pollutants A string vector. Contains the codes of pollutants desired as described in the dataset pollutants_id
#' @param begin A number. Starting year for the data
#' @param end A number. Ending year for the data
#' @return A tibble containing the air pollution data corresponding to the parameters.
#' @examples
#' ep_download(
#'   country = "FR",
#'   cities = "Lyon",
#'   pollutants = "O3",
#'   begin = 2020, end = 2020
#' )
#'
#' @export
#'
#' @importFrom readr read_csv
#' @importFrom utils download.file

ep_download <- function(country = "all", cities = "all", pollutants = "all", begin = "2013", end = "2020") {
  vector_urls <- ep_get_urls(country, cities, pollutants, begin, end)

  data <- NULL
  for (url in vector_urls) {
    temp <- tempfile()
    utils::download.file(url, temp)
    data <- data %>%
      rbind(readr::read_csv(temp))
  }
  unlink(temp)
  return(data)
}
vincentbagilet/europollution documentation built on May 22, 2020, 12:07 a.m.