Temporarily change locale settings.
with_locale(new, code) local_locale(.new = list(), ..., .local_envir = parent.frame())
new, .new |
|
---|---|
code |
|
... | Additional arguments with locale settings. |
.local_envir |
|
[any]
The results of the evaluation of the code
argument.
Setting the LC_ALL
category is currently not implemented.
withr
for examples
## Change locale for time: df <- data.frame( stringsAsFactors = FALSE, date = as.Date(c("2019-01-01", "2019-02-01")), value = c(1, 2) ) with_locale(new = c("LC_TIME" = "es_ES"), code = plot(df$date, df$value))## Compare with: # plot(df$date, df$value) ## Month names: with_locale(new = c("LC_TIME" = "en_GB"), format(ISOdate(2000, 1:12, 1), "%B"))#> [1] "January" "February" "March" "April" "May" "June" #> [7] "July" "August" "September" "October" "November" "December"#> [1] "enero" "febrero" "marzo" "abril" "mayo" #> [6] "junio" "julio" "agosto" "septiembre" "octubre" #> [11] "noviembre" "diciembre"#> decimal_point thousands_sep grouping int_curr_symbol #> "." "" "" "EUR " #> currency_symbol mon_decimal_point mon_thousands_sep mon_grouping #> "Eu" "," "." "\003\003" #> positive_sign negative_sign int_frac_digits frac_digits #> "" "-" "2" "2" #> p_cs_precedes p_sep_by_space n_cs_precedes n_sep_by_space #> "1" "1" "1" "1" #> p_sign_posn n_sign_posn #> "1" "1"#> decimal_point thousands_sep grouping int_curr_symbol #> "." "" "" "USD " #> currency_symbol mon_decimal_point mon_thousands_sep mon_grouping #> "$" "." "," "\003\003" #> positive_sign negative_sign int_frac_digits frac_digits #> "" "-" "2" "2" #> p_cs_precedes p_sep_by_space n_cs_precedes n_sep_by_space #> "1" "0" "1" "0" #> p_sign_posn n_sign_posn #> "1" "1"## Ordering: x <- c("bernard", "bérénice", "béatrice", "boris") with_locale(c(LC_COLLATE = "fr_FR"), sort(x))#> [1] "béatrice" "bérénice" "bernard" "boris"#> [1] "bernard" "boris" "béatrice" "bérénice"