Skip to content

Function %||% fails on R-devel due to _R_CHECK_LENGTH_1_LOGIC2_ #377

@dschlaep

Description

@dschlaep

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions