-
Notifications
You must be signed in to change notification settings - Fork 39
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
FR: Error on empty selection allow_empty = FALSE
has informative class
#347
Comments
Could also improve the base message? f <- function(dat, cols) {
tidyselect::eval_select(
expr = rlang::enquo(cols),
data = dat,
allow_empty = FALSE
)
}
mtcars |> f(c(vs, mpg2))
#> Error in `f()`:
#> ! Can't select columns that don't exist.
#> ✖ Column `mpg2` doesn't exist.
mtcars |> f(c(tidyselect::starts_with("vs")))
#> vs
#> 8
mtcars |> f(c(tidyselect::starts_with("vs2")))
#> Error in `f()`:
#> ! Must select at least one item.
mtcars |> tidyr::pivot_longer(tidyselect::starts_with("vs2"))
#> Error in `tidyr::pivot_longer()`:
#> ! `cols` must select at least one column. Created on 2024-04-25 with reprex v2.1.0 Or add maybe an so that it could throw a message like tidyr does natively?
Currently, tidyr rethrows manually But with my proposal,
Actually, the open issue is #327 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Many of the
eval_select()
errors have a class that lets you know what went wrong, but not the error you get on an empty selection withallow_empty = FALSE
. This would be useful if people want to rethrow the error so that the "Must select at least one item" message is more informative in the context of their function, especially to disambiguate the source of the error if there are multiple tidy-select arguments (e.g. rethrow as "Must select at least one country").Created on 2023-11-30 with reprex v2.0.2
The text was updated successfully, but these errors were encountered: