Debian Codegraph @

R/collate.R

raw
1 #' Collation Order
2 #'
3 #' Temporarily change collation order by changing the value of the
4 #' `LC_COLLATE` locale.
5 #'
6 #' @template with
7 #' @param new `[character(1)]`\cr New collation order
8 #' @param .local_envir `[environment]`\cr The environment to use for scoping.
9 #'
10 #' @section Examples:
11 #'
12 #' ```
13 #' # Modify collation order:
14 #' x <- c("bernard", "bérénice", "béatrice", "boris")
15 #'
16 #' with_collate("fr_FR", sort(x))
17 #' #> [1] "béatrice" "bérénice" "bernard" "boris"
18 #'
19 #' with_collate("C", sort(x))
20 #' #> [1] "bernard" "boris" "béatrice" "bérénice"
21 #' ```
22 #' @export
23 with_collate <- function(new, code) {
24 with_locale(c(LC_COLLATE = new), code)
25 }
26
27 #' @rdname with_collate
28 #' @export
29 local_collate <- function(new = list(), .local_envir = parent.frame()) {
30 local_locale(c(LC_COLLATE = new), .local_envir = .local_envir)
31 }