-
Notifications
You must be signed in to change notification settings - Fork 193
Closed
Description
R-devel introduces as new features:
"Experimentally, setting environment variable _R_CHECK_LENGTH_1_LOGIC2_
will lead to warnings (or errors if the variable is set to a ‘true’ value) when && or || encounter and use arguments of length more than one. " (https://cran.r-project.org/doc/manuals/r-devel/NEWS.html)
The lintr
function %||%
will fail this upcoming check, e.g.,
x <- c("", "", "object_name_linter", "", "", "", "", "", "", "", "")
y <- c("", "", "", "", "", "", "", "", "", "", "")
lintr:::`%||%`(x, y)
with message
Error in is.null(x) || is.na(x) :
'length(x) = 11 > 1' in coercion to 'logical(1)'
Expected result (as obtained with R v3.5.2):
> lintr:::`%||%`(x, y)
[1] "" ""
[3] "object_name_linter" ""
[5] "" ""
[7] "" ""
[9] "" ""
[11] ""
Suggested fix: replace
if (is.null(x) || is.na(x) || length(x) <= 0) {...
with
if (is.null(x) || anyNA(x) || length(x) <= 0) {...
(anyNA
was introduced in R v3.1.0 (https://cran.r-project.org/doc/manuals/r-release/NEWS.html) which is earlier than the lintr
required R version 3.1.1).
russHyde
Metadata
Metadata
Assignees
Labels
No labels