| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/locale.R |
| 3 |
\name{with_locale} |
| 4 |
\alias{with_locale} |
| 5 |
\alias{local_locale} |
| 6 |
\title{Locale settings} |
| 7 |
\usage{ |
| 8 |
with_locale(new, code) |
| 9 |
|
| 10 |
local_locale(.new = list(), ..., .local_envir = parent.frame()) |
| 11 |
} |
| 12 |
\arguments{ |
| 13 |
\item{new, .new}{\verb{[named character]}\cr New locale settings} |
| 14 |
|
| 15 |
\item{code}{\code{[any]}\cr Code to execute in the temporary environment} |
| 16 |
|
| 17 |
\item{...}{Additional arguments with locale settings.} |
| 18 |
|
| 19 |
\item{.local_envir}{\verb{[environment]}\cr The environment to use for scoping.} |
| 20 |
} |
| 21 |
\value{ |
| 22 |
\code{[any]}\cr The results of the evaluation of the \code{code} |
| 23 |
argument. |
| 24 |
} |
| 25 |
\description{ |
| 26 |
Temporarily change locale settings. |
| 27 |
} |
| 28 |
\details{ |
| 29 |
Setting the \code{LC_ALL} category is currently not implemented. |
| 30 |
} |
| 31 |
\examples{ |
| 32 |
|
| 33 |
## Change locale for time: |
| 34 |
df <- data.frame( |
| 35 |
stringsAsFactors = FALSE, |
| 36 |
date = as.Date(c("2019-01-01", "2019-02-01")), |
| 37 |
value = c(1, 2) |
| 38 |
) |
| 39 |
with_locale(new = c("LC_TIME" = "es_ES"), code = plot(df$date, df$value)) |
| 40 |
## Compare with: |
| 41 |
# plot(df$date, df$value) |
| 42 |
|
| 43 |
## Month names: |
| 44 |
with_locale(new = c("LC_TIME" = "en_GB"), format(ISOdate(2000, 1:12, 1), "\%B")) |
| 45 |
with_locale(new = c("LC_TIME" = "es_ES"), format(ISOdate(2000, 1:12, 1), "\%B")) |
| 46 |
|
| 47 |
## Change locale for currencies: |
| 48 |
with_locale(new = c("LC_MONETARY" = "it_IT"), Sys.localeconv()) |
| 49 |
with_locale(new = c("LC_MONETARY" = "en_US"), Sys.localeconv()) |
| 50 |
|
| 51 |
## Ordering: |
| 52 |
x <- c("bernard", "bérénice", "béatrice", "boris") |
| 53 |
with_locale(c(LC_COLLATE = "fr_FR"), sort(x)) |
| 54 |
with_locale(c(LC_COLLATE = "C"), sort(x)) |
| 55 |
|
| 56 |
} |
| 57 |
\seealso{ |
| 58 |
\code{\link{withr}} for examples |
| 59 |
|
| 60 |
\code{\link[=Sys.setlocale]{Sys.setlocale()}} |
| 61 |
} |