R/collate.R

Defines functions local_collate with_collate

Documented in local_collate with_collate

#' Collation Order
#'
#' Temporarily change collation order by changing the value of the
#' `LC_COLLATE` locale.
#'
#' @template with
#' @param new `[character(1)]`\cr New collation order
#' @param .local_envir `[environment]`\cr The environment to use for scoping.
#' @examples
#'
#' # Modify collation order:
#' x <- c("bernard", "bérénice", "béatrice", "boris")
#' with_collate("fr_FR", sort(x))
#' with_collate("C", sort(x))
#'
#' @export
with_collate <- function(new, code) {
  with_locale(c(LC_COLLATE = new), code)
}

#' @rdname with_collate
#' @export
local_collate <- function(new = list(), .local_envir = parent.frame()) {
  local_locale(c(LC_COLLATE = new), .local_envir = .local_envir)
}

Try the withr package in your browser

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

withr documentation built on March 18, 2022, 7:47 p.m.