R/ep_search_country.R

Defines functions ep_search_country

#' Provides the cities and code for a country
#'
#' @param name A string. A portion of the name of the country searched for
#' @return A tibble displaying relevant entries for this country.
#' @examples
#' ep_search_country("austria")
#'
#' @export
#'
#' @importFrom stringr str_detect
#' @importFrom dplyr filter
#' @importFrom rlang .data

ep_search_country <- function(name) {
  if (!is.character(name) | length(name) > 1) {stop("name should be a string")}

  exact_match <- europollution::countries_cities %>%
    dplyr::filter(stringr::str_detect(tolower(.data$countries), name))

  if (nrow(exact_match) == 0) {stop(paste(name, "does not appear in the list of countries"))}
  return(exact_match)
}
vincentbagilet/europollution documentation built on May 22, 2020, 12:07 a.m.