Skip to content

Commit 0ac25c0

Browse files
committed
Accept 0 and 1 for environment variables
Fixes #238
1 parent ae93c2e commit 0ac25c0

File tree

6 files changed

+60
-9
lines changed

6 files changed

+60
-9
lines changed

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# remotes (development version)
22

3+
* Environment variables now accept 0 and 1 as valid values (#238)
4+
35
* remotes now uses locking by default when installing binary packages, which avoids
46
issues when installing binaries that are already open in other R processes
57
(#368)

R/install.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ should_error_for_warnings <- function() {
217217

218218
force_suggests <- Sys.getenv("_R_CHECK_FORCE_SUGGESTS_", "true")
219219

220-
no_errors <- Sys.getenv("R_REMOTES_NO_ERRORS_FROM_WARNINGS", !as.logical(force_suggests))
220+
no_errors <- Sys.getenv("R_REMOTES_NO_ERRORS_FROM_WARNINGS", !config_val_to_logical(force_suggests))
221221

222-
!as.logical(no_errors)
222+
!config_val_to_logical(no_errors)
223223
}

R/utils.R

+14-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ re_match <- function(text, pattern, perl = TRUE, ...) {
263263
}
264264

265265
is_standalone <- function() {
266-
isTRUE(as.logical(Sys.getenv("R_REMOTES_STANDALONE", "false")))
266+
isTRUE(config_val_to_logical(Sys.getenv("R_REMOTES_STANDALONE", "false")))
267267
}
268268

269269
# This code is adapted from the perl MIME::Base64 module https://perldoc.perl.org/MIME/Base64.html
@@ -506,3 +506,16 @@ get_json_sha <- function(text) {
506506
end <- start + attr(m, "capture.length") - 1L
507507
substring(text, start, end)
508508
}
509+
510+
511+
# from tools:::config_val_to_logical
512+
config_val_to_logical <- function (val) {
513+
v <- tolower(val)
514+
if (v %in% c("1", "yes", "true"))
515+
TRUE
516+
else if (v %in% c("0", "no", "false"))
517+
FALSE
518+
else {
519+
NA
520+
}
521+
}

inst/install-github.R

+16-3
Original file line numberDiff line numberDiff line change
@@ -4030,9 +4030,9 @@ function(...) {
40304030

40314031
force_suggests <- Sys.getenv("_R_CHECK_FORCE_SUGGESTS_", "true")
40324032

4033-
no_errors <- Sys.getenv("R_REMOTES_NO_ERRORS_FROM_WARNINGS", !as.logical(force_suggests))
4033+
no_errors <- Sys.getenv("R_REMOTES_NO_ERRORS_FROM_WARNINGS", !config_val_to_logical(force_suggests))
40344034

4035-
!as.logical(no_errors)
4035+
!config_val_to_logical(no_errors)
40364036
}
40374037
# Contents of R/json.R
40384038

@@ -4810,7 +4810,7 @@ function(...) {
48104810
}
48114811

48124812
is_standalone <- function() {
4813-
isTRUE(as.logical(Sys.getenv("R_REMOTES_STANDALONE", "false")))
4813+
isTRUE(config_val_to_logical(Sys.getenv("R_REMOTES_STANDALONE", "false")))
48144814
}
48154815

48164816
# This code is adapted from the perl MIME::Base64 module https://perldoc.perl.org/MIME/Base64.html
@@ -5053,6 +5053,19 @@ function(...) {
50535053
end <- start + attr(m, "capture.length") - 1L
50545054
substring(text, start, end)
50555055
}
5056+
5057+
5058+
# from tools:::config_val_to_logical
5059+
config_val_to_logical <- function (val) {
5060+
v <- tolower(val)
5061+
if (v %in% c("1", "yes", "true"))
5062+
TRUE
5063+
else if (v %in% c("0", "no", "false"))
5064+
FALSE
5065+
else {
5066+
NA
5067+
}
5068+
}
50565069

50575070

50585071
## Standalone mode, make sure that we restore the env var on exit

install-github.R

+16-3
Original file line numberDiff line numberDiff line change
@@ -4030,9 +4030,9 @@ function(...) {
40304030

40314031
force_suggests <- Sys.getenv("_R_CHECK_FORCE_SUGGESTS_", "true")
40324032

4033-
no_errors <- Sys.getenv("R_REMOTES_NO_ERRORS_FROM_WARNINGS", !as.logical(force_suggests))
4033+
no_errors <- Sys.getenv("R_REMOTES_NO_ERRORS_FROM_WARNINGS", !config_val_to_logical(force_suggests))
40344034

4035-
!as.logical(no_errors)
4035+
!config_val_to_logical(no_errors)
40364036
}
40374037
# Contents of R/json.R
40384038

@@ -4810,7 +4810,7 @@ function(...) {
48104810
}
48114811

48124812
is_standalone <- function() {
4813-
isTRUE(as.logical(Sys.getenv("R_REMOTES_STANDALONE", "false")))
4813+
isTRUE(config_val_to_logical(Sys.getenv("R_REMOTES_STANDALONE", "false")))
48144814
}
48154815

48164816
# This code is adapted from the perl MIME::Base64 module https://perldoc.perl.org/MIME/Base64.html
@@ -5053,6 +5053,19 @@ function(...) {
50535053
end <- start + attr(m, "capture.length") - 1L
50545054
substring(text, start, end)
50555055
}
5056+
5057+
5058+
# from tools:::config_val_to_logical
5059+
config_val_to_logical <- function (val) {
5060+
v <- tolower(val)
5061+
if (v %in% c("1", "yes", "true"))
5062+
TRUE
5063+
else if (v %in% c("0", "no", "false"))
5064+
FALSE
5065+
else {
5066+
NA
5067+
}
5068+
}
50565069

50575070

50585071
## Standalone mode, make sure that we restore the env var on exit

tests/testthat/test-install.R

+10
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,26 @@ test_that("should_error_for_warnings works", {
113113
withr::with_envvar(c("R_REMOTES_NO_ERRORS_FROM_WARNINGS" = "true", "_R_CHECK_FORCE_SUGGESTS_" = NA),
114114
expect_false(should_error_for_warnings())
115115
)
116+
withr::with_envvar(c("R_REMOTES_NO_ERRORS_FROM_WARNINGS" = "1", "_R_CHECK_FORCE_SUGGESTS_" = NA),
117+
expect_false(should_error_for_warnings())
118+
)
116119

117120
# If no errors unset, and force_suggests false, should error -> FALSE
118121
withr::with_envvar(c("R_REMOTES_NO_ERRORS_FROM_WARNINGS" = NA, "_R_CHECK_FORCE_SUGGESTS_" = "false"),
119122
expect_false(should_error_for_warnings())
120123
)
124+
withr::with_envvar(c("R_REMOTES_NO_ERRORS_FROM_WARNINGS" = NA, "_R_CHECK_FORCE_SUGGESTS_" = "0"),
125+
expect_false(should_error_for_warnings())
126+
)
121127

122128
# If no errors unset, and force_suggests true, should error -> TRUE
123129
withr::with_envvar(c("R_REMOTES_NO_ERRORS_FROM_WARNINGS" = NA, "_R_CHECK_FORCE_SUGGESTS_" = "true"),
124130
expect_true(should_error_for_warnings())
125131
)
132+
withr::with_envvar(c("R_REMOTES_NO_ERRORS_FROM_WARNINGS" = NA, "_R_CHECK_FORCE_SUGGESTS_" = "1"),
133+
expect_true(should_error_for_warnings())
134+
)
135+
126136
})
127137

128138
test_that("normalize_build_opts works", {

0 commit comments

Comments
 (0)