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
Error message for select()
when column doesn't exist
#6200
Comments
It now says library(dplyr, warn.conflicts = FALSE)
df <- tibble(x = 1:2, y = 3:4)
df %>% select(z)
#> Error in `select()`:
#> ! Can't subset columns that don't exist.
#> ✖ Column `z` doesn't exist. Created on 2022-07-21 by the reprex package (v2.0.1) Which I think is about as good as we can get, without customising the underlying vctrs error which would be a lot of work, for relatively little gain, IMO. |
This might not be that hard actually. tidyselect is already renaming it to tidyselect:::with_subscript_errors
#> function (expr, type = "select", call = caller_env())
#> {
#> tryCatch(expr, vctrs_error_subscript = function(cnd) {
#> cnd$subscript_action <- subscript_action(type)
#> cnd$subscript_elt <- "column"
#> cnd_signal(cnd)
#> })
#> }
#> <bytecode: 0x7f7dbd5df4f0>
#> <environment: namespace:tidyselect> tidyselect:::subscript_action
#> function (type)
#> {
#> switch(validate_type(type), select = "subset", rename = "rename",
#> pull = "extract")
#> }
#> <bytecode: 0x7f7ddc4e69e0>
#> <environment: namespace:tidyselect> So maybe tidyselect should say We'd have to make library(dplyr, warn.conflicts = FALSE)
df <- tibble(x = 1:2, y = 3:4)
withCallingHandlers(
select(df, z),
vctrs_error_subscript_oob = function(cnd) {
cnd$subscript_action <- "select"
rlang::cnd_signal(cnd)
}
)
#> Error in `cnd_subscript_action()`:
#> ! Internal error: `cnd$subscript_action` must be one of `subset`, `extract`, `assign`, `rename`, `remove`, or `negate`. Alternatively we can also catch and rethrow the error in |
That sounds good. We'll need a change in both vctrs and tidyselect, I've opened issues. |
FWIW I stand by my original comment that this is more trouble than its worth. Having to change three packages in concert to modify a single word in an error message that is already pretty good doesn't feel like a great payoff to me. |
Fine by me |
See below for a reprex for selecting a column that doesn't exist:
Created on 2022-02-27 by the reprex package (v2.0.1)
I think the error should say
Can't select columns that don't exist
sincesubset
is not the verb used in the code, and it actually meansfilter()
in base R.The text was updated successfully, but these errors were encountered: