You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 with allow_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").
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 #> 8mtcars|> 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.
# The call in tidyr could become
cols <- tidyselect::eval_select(
expr = enquo(cols),
data = data[unique(names(data))],
allow_rename = FALSE,
allow_empty = FALSE,
error_arg = "cols",
error_call = error_call
)
#> `cols` must select at least one column
error_arg was proposed in #282 (comment), is there plan to implement it?
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: