-
Notifications
You must be signed in to change notification settings - Fork 286
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
Provide clear error message when col_select includes no columns #1419
Comments
Looks like we now get nice messages for free thanks to tidyselect improvements: library(readr)
read_csv(readr_example("mtcars.csv"), col_select = all_of("x"))
#> Error in `all_of()`:
#> ! Can't subset columns that don't exist.
#> ✖ Column `x` doesn't exist. Created on 2023-07-31 with reprex v2.0.2 |
In the case I struggled with (where the selection is empty) the error message is not quite as nice as it is not clear what the library(readr)
read_csv(readr_example("mtcars.csv"), col_select = all_of(""))
#> Error in `all_of()`:
#> ! Can't subset columns.
#> ✖ Subscript can't contain the empty string.
#> ✖ It has an empty string at location 1.
#> Backtrace:
#> ▆
#> 1. ├─readr::read_csv(readr_example("mtcars.csv"), col_select = all_of(""))
#> 2. │ └─vroom::vroom(...)
#> 3. │ └─vroom:::vroom_(...)
#> 4. ├─vroom (local) `<fn>`(`<col_spec>`, 11L, `<chr>`, all_of(""), "unique")
#> 5. │ ├─names(spec$cols) %in% ...
#> 6. │ └─tidyselect::vars_select(names(spec$cols), !!col_select, .strict = FALSE)
#> 7. │ └─tidyselect:::eval_select_impl(...)
#> 8. │ ├─tidyselect:::with_subscript_errors(...)
#> 9. │ │ └─rlang::try_fetch(...)
#> 10. │ │ └─base::withCallingHandlers(...)
#> 11. │ └─tidyselect:::vars_select_eval(...)
#> 12. │ └─tidyselect:::walk_data_tree(expr, data_mask, context_mask)
#> 13. │ └─tidyselect:::eval_c(expr, data_mask, context_mask)
#> 14. │ └─tidyselect:::reduce_sels(node, data_mask, context_mask, init = init)
#> 15. │ └─tidyselect:::walk_data_tree(new, data_mask, context_mask)
#> 16. │ └─tidyselect:::eval_context(expr, context_mask, call = error_call)
#> 17. │ ├─tidyselect:::with_chained_errors(...)
#> 18. │ │ └─rlang::try_fetch(...)
#> 19. │ │ ├─base::tryCatch(...)
#> 20. │ │ │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#> 21. │ │ │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#> 22. │ │ │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#> 23. │ │ └─base::withCallingHandlers(...)
#> 24. │ └─rlang::eval_tidy(as_quosure(expr, env), context_mask)
#> 25. ├─tidyselect::all_of("")
#> 26. │ └─tidyselect:::as_indices_impl(x, vars = vars, strict = TRUE)
#> 27. │ └─tidyselect:::chr_as_locations(x, vars, call = call, arg = arg)
#> 28. │ └─vctrs::vec_as_location(...)
#> 29. └─vctrs (local) `<fn>`()
#> 30. └─vctrs:::stop_subscript_empty(i = i, call = call)
#> 31. └─rlang::cnd_signal(...) Created on 2023-08-02 with reprex v2.0.2 |
It says |
When col_select contains no columns, it would be great to get a clear error message (or possibly just an empty dataframe) ... in any case, the current cryptic error message made debugging rather hard when this happened in a real context.
Created on 2022-08-21 by the reprex package (v2.0.1)
The text was updated successfully, but these errors were encountered: