Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dschlaep opened this issue Mar 11, 2019 · 2 comments
Closed

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

dschlaep opened this issue Mar 11, 2019 · 2 comments

Comments

@dschlaep
Copy link

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

dschlaep added a commit to DrylandEcology/rSFSW2 that referenced this issue Mar 11, 2019
- `lintr` fails R-devel `_R_CHECK_LENGTH_1_LOGIC2_`, see r-lib/lintr#377
- temporarily disable `_R_CHECK_LENGTH_1_LOGIC2_` during our code style unit checks

--> revert this commit once `lintr` addressed  r-lib/lintr#377
@russHyde
Copy link
Collaborator

Ref #395

@russHyde
Copy link
Collaborator

Fixed in #395

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants