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

Potential bug with if_any()- returns TRUE if no columns are selected #7074

Closed
ks8997 opened this issue Aug 21, 2024 · 2 comments
Closed

Potential bug with if_any()- returns TRUE if no columns are selected #7074

ks8997 opened this issue Aug 21, 2024 · 2 comments

Comments

@ks8997
Copy link

ks8997 commented Aug 21, 2024

The if_any() function returns TRUE if we pass an empty vector of columns. I think this behavior is unexpected and may introduce subtle bugs if your tidyselect function does not match any columns. I think it should possibly return an error.

iris %>%
    mutate(z = if_any(c(), ~ . > 4000)) # returns all TRUE

iris %>%
    mutate(z = if_any(starts_with("XYZ"), ~ . > 4000)) # returns all TRUE
@DavisVaughan
Copy link
Member

This was actually just fixed by #7072

The correct behavior is actually to return all FALSE here, consistent with the base function any() when no inputs are provided. I don't think we want to error, we just want consistent and explainable behavior

@ks8997
Copy link
Author

ks8997 commented Aug 22, 2024

@DavisVaughan Thanks for explaining. But, I don't think this behavior is fixed. I updated to the latest version and using if_any in mutate with zero cols incorrectly returns all TRUE, although I think it works correctly inside filter. You can try the examples I posted above.

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