R/cl_locale.R

Defines functions cl_locale

Documented in cl_locale

#' Get the locale to use with the codelist
#'
#' @param codelist a \code{\link{codelist}} object or a \code{data.frame} that
#' is a valid code list.
#'
#' @param preferred the preferred locale. If missing or not present in the 
#' code list, the first locale in the code list will be used.
#'
#' @return
#' A character vector of length 1 with the locale. Can be \code{NA} when the 
#' codelist does not have locales.
#'
#' @export
cl_locale <- function(codelist, 
    preferred = getOption("CLLOCALE", NA_character_)) {
  locales <- cl_locales(codelist)
  if (preferred %in% locales) {
    preferred
  } else {
    utils::head(locales, 1)
  }
}

Try the codelist package in your browser

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

codelist documentation built on April 12, 2025, 2:25 a.m.