Skip to content

Commit

Permalink
Support also R_STARTUP_RDATA="warn,remove" and "warn,replace"
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikBengtsson committed Nov 5, 2024
1 parent a66afe3 commit 283b990
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 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.22.0-9009
Version: 0.22.0-9010
Title: Friendly R Startup Configuration
Depends: R (>= 2.14.0)
Suggests: commonmark, tools, tcltk
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

* Add support for `R_STARTUP_RDATA="warn"`, which will warn about the
existance of a `.RData` file with information of its size and
timestamp.
timestamp. This can be combined with `"remove"` and `"rename"`,
e.g. `R_STARTUP_RDATA="warn,remove"`.


# Version 0.22.0 (2024-07-29)
Expand Down
15 changes: 11 additions & 4 deletions R/startup.R
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,20 @@ startup <- function(sibling = FALSE, all = FALSE,
rdata <- fallback
}
}
} else if (rdata[1] == "warn") {
if (debug) logf("- Warn about %s", f_info)
warning(sprintf("Detected %s, which R will attempt to load at the end of this startup process [R_STARTUP_RDATA/startup.rdata=%s]", f_info, rdata0), immediate. = TRUE, call. = FALSE)
rdata <- rdata[2L]
if (is.na(rdata)) rdata <- "default"
}

## At this point, we should have at most one element in 'rdata'
stop_if_not(length(rdata) == 1L, !is.na(rdata))
if (length(rdata) != 1L) {
stop(sprintf("Unknown value (%s) of %s/%s",
squote(rdata0), squote("R_STARTUP_RDATA"),
squote("startup.rdata")))
}
stop_if_not(!is.na(rdata))

if (rdata == "remove") {
if (debug) logf("- Skipping %s by removing it", f_info)
Expand All @@ -463,9 +473,6 @@ startup <- function(sibling = FALSE, all = FALSE,
if (!has_RData) {
warning(sprintf("Skipped %s by renaming it to %s [R_STARTUP_RDATA/startup.rdata=%s]", squote(f_norm), f_new_info, rdata0), call. = FALSE)
}
} else if (rdata == "warn") {
if (debug) logf("- Warn about %s", f_info)
warning(sprintf("Detected %s, which R will attempt to load at the end of this startup process [R_STARTUP_RDATA/startup.rdata=%s]", f_info, rdata0), immediate. = TRUE, call. = FALSE)
} else if (rdata != "default") {
warning(sprintf("Ignoring unknown value (%s) of %s/%s",
squote(rdata0), squote("R_STARTUP_RDATA"),
Expand Down

0 comments on commit 283b990

Please sign in to comment.