#' Provides the code for a pollutant based on its name
#'
#' @param name A string. A portion of the name of the pollutant whose code is searched for
#' @return A tibble displaying entries in \code{pollutants_id} which contain \code{name} in their label description
#' @examples
#' ep_search_pollutant("sulphur")
#'
#' @export
#'
#' @importFrom stringr str_detect
#' @importFrom dplyr filter
#' @importFrom rlang .data
ep_search_pollutant <- function(name) {
if (!is.character(name) | length(name) > 1) {stop("name should be a string")}
exact_match <- europollution::pollutants_id %>%
dplyr::filter(stringr::str_detect(tolower(.data$label), name))
if (nrow(exact_match) == 0) {stop(paste(name, "does not appear in the list of pollutants"))}
return(exact_match)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.