Skip to content

Commit 797fdcf

Browse files
Now WARDEN is only patched during 'R CMD check'
1 parent 81a1580 commit 797fdcf

File tree

1 file changed

+67
-2
lines changed

1 file changed

+67
-2
lines changed

R/zzz.R

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,68 @@
1+
## From R.utils 2.7.0 (2018-08-26)
2+
queryRCmdCheck <- function(...) {
3+
evidences <- list()
4+
5+
# Command line arguments
6+
args <- commandArgs()
7+
8+
evidences[["vanilla"]] <- is.element("--vanilla", args)
9+
10+
# Check the working directory
11+
pwd <- getwd()
12+
dirname <- basename(pwd)
13+
parent <- basename(dirname(pwd))
14+
pattern <- ".+[.]Rcheck$"
15+
16+
# Is 'R CMD check' checking tests?
17+
evidences[["tests"]] <- (
18+
grepl(pattern, parent) && grepl("^tests(|_.*)$", dirname)
19+
)
20+
21+
# Is the current working directory as expected?
22+
evidences[["pwd"]] <- (evidences[["tests"]] || grepl(pattern, dirname))
23+
24+
# Is 'R CMD check' checking examples?
25+
evidences[["examples"]] <- is.element("CheckExEnv", search())
26+
27+
# SPECIAL: win-builder?
28+
evidences[["win-builder"]] <- (.Platform$OS.type == "windows" && grepl("Rterm[.]exe$", args[1]))
29+
30+
if (evidences[["win-builder"]]) {
31+
n <- length(args)
32+
if (all(c("--no-save", "--no-restore", "--no-site-file", "--no-init-file") %in% args)) {
33+
evidences[["vanilla"]] <- TRUE
34+
}
35+
36+
if (grepl(pattern, parent)) {
37+
evidences[["pwd"]] <- TRUE
38+
}
39+
}
40+
41+
if (!evidences$vanilla || !evidences$pwd) {
42+
res <- "notRunning"
43+
} else if (evidences$tests) {
44+
res <- "checkingTests"
45+
} else if (evidences$examples) {
46+
res <- "checkingExamples"
47+
} else {
48+
res <- "notRunning"
49+
}
50+
51+
attr(res, "evidences") <- evidences
52+
53+
res
54+
}
55+
56+
inRCmdCheck <- local({
57+
.cache <- NULL
58+
function() {
59+
if (is.null(.cache)) {
60+
.cache <<- (queryRCmdCheck() != "notRunning")
61+
}
62+
.cache
63+
}
64+
})
65+
166
future_has_evalFuture <- local({
267
res <- NULL
368
function() {
@@ -15,8 +80,8 @@ patch_expressions <- function() {
1580
if (is.null(patches)) {
1681
patches <- NA_character_
1782
if (future_has_evalFuture()) {
18-
## Package 'WARDEN'
19-
if ("WARDEN" %in% loadedNamespaces()) {
83+
## Package 'WARDEN', if 'R CMD check' is running
84+
if ("WARDEN" %in% loadedNamespaces() && inRCmdCheck()) {
2085
patches <- c(patches, "WARDEN")
2186
}
2287
}

0 commit comments

Comments
 (0)