Skip to content

Commit

Permalink
startup() gained argument 'encoding' [#132]
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikBengtsson committed Apr 19, 2024
1 parent b22bde1 commit 795b6d1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: startup
Version: 0.21.0-9002
Version: 0.21.0-9003
Title: Friendly R Startup Configuration
Depends: R (>= 2.14.0)
Suggests: commonmark, tools, tcltk
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## New Features

* `startup()` gained argument `encoding`, which controls the encoding
used to parse the R startup files.

* Now `sysinfo()` return also flag `webr`, which indicates whether R
runs via WebR or not.

Expand Down
8 changes: 6 additions & 2 deletions R/startup.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#' complete. The default is to keep `startup.session.*` options
#' as recorded by [startup_session_options()].
#'
#' @param encoding The encodingto use when parsing the R startup files.
#' See [base::parse()] for more details.
#'
#' @param check If `TRUE`, then the content of startup files are validated.
#'
#' @param unload If `TRUE`, then the package is unloaded afterward, otherwise
Expand Down Expand Up @@ -81,6 +84,7 @@ startup <- function(sibling = FALSE, all = FALSE,
on_error = c("error", "warning", "immediate.warning",
"message", "ignore"),
keep = c("options"), check = NA, unload = TRUE, skip = NA,
encoding = getOption("encoding"),
dryrun = NA, debug = dryrun) {
## Is startup::startup() fully disabled?
disable <- as.logical(Sys.getenv("R_STARTUP_DISABLE", "FALSE"))
Expand Down Expand Up @@ -279,7 +283,7 @@ startup <- function(sibling = FALSE, all = FALSE,
code <- getOption("startup.init", code)
if (nzchar(code)) {
logf("Processing R_STARTUP_INIT/startup.init=%s:", squote(code))
expr <- tryCatch(parse(text = code), error = identity)
expr <- tryCatch(parse(text = code, encoding = encoding), error = identity)
if (inherits(expr, "error")) {
msg <- sprintf("Syntax error in 'R_STARTUP_INIT'/'startup.init': %s", squote(code))
logf(paste("- [SKIPPED]", msg))
Expand Down Expand Up @@ -321,7 +325,7 @@ startup <- function(sibling = FALSE, all = FALSE,
message(msg)
}
}
expr <- tryCatch(parse(file = f), error = identity)
expr <- tryCatch(parse(file = f, encoding = encoding), error = identity)
if (inherits(expr, "error")) {
msg <- sprintf("Syntax error in 'R_STARTUP_INIT'/'startup.init': %s", squote(code))
logf(paste("- [SKIPPED]", msg))
Expand Down
4 changes: 4 additions & 0 deletions man/startup.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 795b6d1

Please sign in to comment.