-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
if_else throws false must be a vector, not NULL. error for dplyr 1.1.0 #6730
Comments
dplyr::if_else(TRUE, NULL, NULL)
#> NULL
dplyr::if_else(TRUE, 1, NULL)
#> [1] 1
dplyr::if_else(TRUE, NULL, 1)
#> Error in `dplyr::if_else()`:
#> ! `false` must be NULL, not a double vector. In 1.1.0, these all error consistently: dplyr::if_else(TRUE, NULL, NULL)
#> Error in `dplyr::if_else()`:
#> ! `true` must be a vector, not `NULL`.
dplyr::if_else(TRUE, 1, NULL)
#> Error in `dplyr::if_else()`:
#> ! `false` must be a vector, not `NULL`.
dplyr::if_else(TRUE, NULL, 1)
#> Error in `dplyr::if_else()`:
#> ! `true` must be a vector, not `NULL`. I don't think we ever intended for
Also note that # Works
ifelse(TRUE, 1, NULL)
#> [1] 1
# Doesn't work
ifelse(FALSE, 1, NULL)
#> Warning in rep(no, length.out = len): 'x' is NULL so the result will be NULL
#> Error in ans[npos] <- rep(no, length.out = len)[npos]: replacement has length zero
ifelse(c(TRUE, FALSE), 1, NULL)
#> Warning in rep(no, length.out = len): 'x' is NULL so the result will be NULL
#> Error in ans[npos] <- rep(no, length.out = len)[npos]: replacement has length zero This makes I've added a retrospective NEWS bullet about I think all of this together is sufficient justification for this change, but I appreciate that you followed up to get more clarification |
Thanks a lot for the detailed reply, this is what I tried to achieve - a discussion on why, things are more clear now, and I understand the reasoning of why things have been changed. In the contexts I used it so far, even when NULL was involved, I didnt come across all these edge cases, it basically worked as I intuitively expected, therefore my surprise now with the new(er) release. Thanks for your effort and retrospective change, I think this will be useful in the future for those who wonder as well. |
I posted an issue yesterday (#6728) but it was closed immediately after the first reply, which I felt was unjustified because my response and argument is not being replied to anymore because the issue is closed. I therefore would like to reopen it here again for a discussion, and I am hoping for a more fruitful solution.
Between dplyr 1.0.0 and 1.1.0, an undocumented (unless I oversaw it) and breaking change has been included into
if_else
that I find not very useful personally and which forced me and others to go back to base Rifelse
, and I wanted to learn what was the motivation for it. In essence, it seems "Thetrue
andfalse
arguments are always evaluated, regardless of whether their values are seen in the result, which causes an error in dplyr 1.1.0 whenNULL
is involved. I'd appreciate a discussion why this is a useful change, because it worked differently and "as expected" until dplyr 1.0.0. Thank youThe text was updated successfully, but these errors were encountered: