R/common-name.R

Defines functions fbc_common_name

Documented in fbc_common_name

#' Common Name
#'
#' @param x A character vector of the provincial fish codes.
#'
#' @return A character vector of the corresponding common names.
#' @export
#'
#' @examples
#' fbc_common_name(c("AF", "WSG", NA, "AF", "NOTACODE"))
fbc_common_name <- function(x) {
  stopifnot(is.vector(x, "character"))

  if(!length(x)) return(character(0))

  y <- fishbc::freshwaterfish$CommonName
  names(y) <- fishbc::freshwaterfish$Code
  y <- y[x]
  names(y) <- NULL
  y
}

Try the fishbc package in your browser

Any scripts or data that you put into this service are public.

fishbc documentation built on May 13, 2021, 1:07 a.m.