Skip to content

Commit 3483519

Browse files
REVDEP: Add R_BASE_STARTUP script 'revdep/test_with_global_handlers.R' [ci skip]
1 parent 5b03b34 commit 3483519

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

revdep/test_with_global_handlers.R

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#' Run Reverse Package Dependency Checks with the Global Progression Handler Enabled
2+
#'
3+
#' @usage
4+
#' R_BASE_STARTUP="$PWD/revdep/test_with_global_handlers.R" revdep/run.R
5+
#'
6+
#' @param R_BASE_STARTUP (environment variable) An absolute path to an R
7+
#' script that should be loaded when the \pkg{base} package is loaded.
8+
#'
9+
#' @details
10+
#' This script writes log output to the "${R_BASE_STARTUP}.log" file,
11+
#' unless "${R_BASE_STARTUP_FILE}" is set in case that is used instead.
12+
#'
13+
#' @section Requirements:
14+
#' For this to work, the \file{Rprofile} of the \pkg{base} package must
15+
#' be tweaked. Specifically, append:
16+
#'
17+
#' ```
18+
#' local(if(nzchar(f<-Sys.getenv("R_BASE_STARTUP"))) source(f))
19+
#' ```
20+
#'
21+
#' to file:
22+
#'
23+
#' ```
24+
#' rprofile <- system.file(package = "base", "R", "Rprofile")
25+
#' ```
26+
#'
27+
#' This requires write permissions to that file.
28+
#'
29+
#' @examples
30+
#' R_BASE_STARTUP="$PWD/revdep/test_with_global_handlers.R" revdep/run.R
31+
#'
32+
#' @importFrom utils packageVersion
33+
#' @importFrom progressr handlers
34+
local({
35+
log_ <- function(..., prefix = sprintf("[%s/%d]: ", Sys.time(), Sys.getpid()), newline = TRUE, tee = stdout(), logfile = Sys.getenv("R_BASE_STARTUP_FILE")) {
36+
if (!nzchar(logfile)) {
37+
logfile <- Sys.getenv("R_BASE_STARTUP")
38+
logfile <- if (nzchar(logfile)) sprintf("%s.log", logfile) else NULL
39+
}
40+
msg <- sprintf(...)
41+
if (newline) msg <- paste(msg, "\n", sep = "")
42+
msg <- paste(prefix, msg, sep = "")
43+
msg <- paste(msg, collapse="")
44+
if (!is.null(tee)) cat(msg, file = tee, append = TRUE)
45+
if (!is.null(logfile)) cat(msg, file = logfile, append = TRUE)
46+
}
47+
48+
## R CMD check package tests?
49+
if (nzchar(testfile <- Sys.getenv("R_TESTS"))) {
50+
log_("commandArgs()=%s", paste(commandArgs(), collapse = " "))
51+
log_("R_LIBS_USER=%s", sQuote(Sys.getenv("R_LIBS_USER")))
52+
log_("R_LIBS_SITE=%s", sQuote(Sys.getenv("R_LIBS_SITE")))
53+
log_("R_LIBS=%s", sQuote(Sys.getenv("R_LIBS")))
54+
log_(".libPaths()=%s", paste(.libPaths(), collapse = " "))
55+
log_("R_TESTS=%s", sQuote(testfile))
56+
log_("getwd()=%s", getwd())
57+
58+
## Enable global progression handlers, if available
59+
if (requireNamespace("progressr", quietly = TRUE) && utils::packageVersion("progressr") >= "0.6.0-9001") {
60+
progressr::handlers(global = TRUE)
61+
log_("progressr::handlers(global=NA)=%s", progressr::handlers(global=NA))
62+
}
63+
}
64+
})

0 commit comments

Comments
 (0)