-
Notifications
You must be signed in to change notification settings - Fork 40
Closed
Description
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").
library(tidyselect)
eval_select(quote(any_of('z')), list(x = 1), allow_empty = FALSE) |>
rlang::catch_cnd() |>
class()
#> [1] "rlang_error" "error" "condition"
eval_select(c(a = 'x'), list(x = 1), allow_rename = FALSE) |>
rlang::catch_cnd() |>
class()
#> [1] "tidyselect:::error_disallowed_rename"
#> [2] "rlang_error"
#> [3] "error"
#> [4] "condition"
eval_select('z', list(x = 1)) |>
rlang::catch_cnd() |>
class()
#> [1] "vctrs_error_subscript_oob" "vctrs_error_subscript"
#> [3] "rlang_error" "error"
#> [5] "condition"
eval_select(list(1), list(x = 1)) |>
rlang::catch_cnd() |>
class()
#> [1] "vctrs_error_subscript_type" "vctrs_error_subscript"
#> [3] "rlang_error" "error"
#> [5] "condition"
Created on 2023-11-30 with reprex v2.0.2
Metadata
Metadata
Assignees
Labels
No labels