Skip to content

Commit

Permalink
check for valid locale variables set via options()
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Baumann committed Sep 26, 2023
1 parent 659500e commit a57e6a1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
22 changes: 15 additions & 7 deletions R/find_rev.R
Original file line number Diff line number Diff line change
Expand Up @@ -463,16 +463,24 @@ get_system_pkgs(system_pkgs))
}

generate_locale_variables <- function() {
locale_defaults <- list(
LANG = "en_US.UTF-8",
LC_ALL = "en_US.UTF-8",
LC_TIME = "en_US.UTF-8",
LC_MONETARY = "en_US.UTF-8",
LC_PAPER = "en_US.UTF-8"
)
locale_variables <- getOption(
"rix.nix_locale_variables",
default = list(
LANG = "en_US.UTF-8",
LC_ALL = "en_US.UTF-8",
LC_TIME = "en_US.UTF-8",
LC_MONETARY = "en_US.UTF-8",
LC_PAPER = "en_US.UTF-8"
)
default = locale_defaults
)
valid_vars <- all(names(locale_variables) %in% names(locale_defaults))
if (!isTRUE(valid_vars)) {
stop("`options(rix.nix_locale_variables = list())` ",
"only allows the following element names (locale variables):\n",
paste(names(locale_defaults), collapse = "; "),
call. = FALSE)
}
locale_vars <- paste(
Map(function(x, nm) paste0(nm, ' = ', '"', x, '"'),
nm = names(locale_variables), x = locale_variables),
Expand Down
22 changes: 15 additions & 7 deletions dev/build_envs.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -547,16 +547,24 @@ get_system_pkgs(system_pkgs))
}
generate_locale_variables <- function() {
locale_defaults <- list(
LANG = "en_US.UTF-8",
LC_ALL = "en_US.UTF-8",
LC_TIME = "en_US.UTF-8",
LC_MONETARY = "en_US.UTF-8",
LC_PAPER = "en_US.UTF-8"
)
locale_variables <- getOption(
"rix.nix_locale_variables",
default = list(
LANG = "en_US.UTF-8",
LC_ALL = "en_US.UTF-8",
LC_TIME = "en_US.UTF-8",
LC_MONETARY = "en_US.UTF-8",
LC_PAPER = "en_US.UTF-8"
)
default = locale_defaults
)
valid_vars <- all(names(locale_variables) %in% names(locale_defaults))
if (!isTRUE(valid_vars)) {
stop("`options(rix.nix_locale_variables = list())` ",
"only allows the following element names (locale variables):\n",
paste(names(locale_defaults), collapse = "; "),
call. = FALSE)
}
locale_vars <- paste(
Map(function(x, nm) paste0(nm, ' = ', '"', x, '"'),
nm = names(locale_variables), x = locale_variables),
Expand Down

0 comments on commit a57e6a1

Please sign in to comment.