Select column that are exactly the names captured unevaluated from .... This is to provide a simple interface that reliably uses non-standard captured names (and not consequences of further evaluation). Please see https://win-vector.com/2018/09/23/a-subtle-flaw-in-some-popular-r-nse-interfaces/ for some discussion. Also accepts -name notation, but not integers or functions of columns. Does not look at argument names (so can not be used to rename columns).

select_nse(.data, ...)

Arguments

.data

data frame or tbl to select columns from.

...

unevaluated symbols to use as column names.

Examples

y <- "x" # returns y-column dplyr::select(data.frame(x = 1, y = 2), y)
#> y #> 1 2
# returns x-column (very confusing!) dplyr::select(data.frame(x = 1), y)
#> Note: Using an external vector in selections is ambiguous. #> Use `all_of(y)` instead of `y` to silence this message. #> See <https://tidyselect.r-lib.org/reference/faq-external-vector.html>. #> This message is displayed once per session.
#> x #> 1 1
# returns y-column select_nse(data.frame(x = 1, y = 2), y)
#> y #> 1 2
# deletes wrong column! dplyr::select(data.frame(x = 1, z = 3), -y)
#> z #> 1 3
# throws when y is not the name of a column (good) tryCatch( select_nse(data.frame(x = 1), y), error = function(e) { e } )
#> <error/vctrs_error_subscript_oob> #> Can't subset columns that don't exist. #> x Column `y` doesn't exist. #> Backtrace: #> 1. base::tryCatch(...) #> 13. pkgdown::build_site(...) #> 14. pkgdown:::build_site_local(...) #> 15. pkgdown::build_reference(...) #> 16. purrr::map(...) #> 17. pkgdown:::.f(.x[[i]], ...) #> 19. pkgdown:::data_reference_topic(...) #> 20. pkgdown:::run_examples(...) #> 21. pkgdown:::highlight_examples(code, topic, env = env) #> 22. downlit::evaluate_and_highlight(...) #> 23. evaluate::evaluate(code, child_env(env), new_device = TRUE) #> 24. evaluate:::evaluate_call(...) #> 34. [ base::eval(...) ] with 1 more call #> 40. seplyr::select_nse(data.frame(x = 1), y) #> 41. seplyr::select_se(.data, colNames) #> 43. dplyr:::select.data.frame(.data, !!!colSyms) #> 44. tidyselect::eval_select(expr(c(...)), .data) #> 45. tidyselect:::eval_select_impl(...) #> 53. tidyselect:::vars_select_eval(...) #> 54. tidyselect:::walk_data_tree(expr, data_mask, context_mask) #> 55. tidyselect:::eval_c(expr, data_mask, context_mask) #> 56. tidyselect:::reduce_sels(node, data_mask, context_mask, init = init) #> 57. tidyselect:::walk_data_tree(new, data_mask, context_mask) #> 58. tidyselect:::as_indices_sel_impl(...) #> 59. tidyselect:::as_indices_impl(x, vars, strict = strict) #> 60. tidyselect:::chr_as_locations(x, vars) #> 61. vctrs::vec_as_location(x, n = length(vars), names = vars) #> 63. vctrs:::stop_subscript_oob(...) #> 64. vctrs:::stop_subscript(...)
#' # throws when y is not the name of a column (good) tryCatch( select_nse(data.frame(x = 1, z = 3), -y), error = function(e) { e } )
#> <error/vctrs_error_subscript_oob> #> Can't subset columns that don't exist. #> x Column `y` doesn't exist. #> Backtrace: #> 1. base::tryCatch(...) #> 13. pkgdown::build_site(...) #> 14. pkgdown:::build_site_local(...) #> 15. pkgdown::build_reference(...) #> 16. purrr::map(...) #> 17. pkgdown:::.f(.x[[i]], ...) #> 19. pkgdown:::data_reference_topic(...) #> 20. pkgdown:::run_examples(...) #> 21. pkgdown:::highlight_examples(code, topic, env = env) #> 22. downlit::evaluate_and_highlight(...) #> 23. evaluate::evaluate(code, child_env(env), new_device = TRUE) #> 24. evaluate:::evaluate_call(...) #> 34. [ base::eval(...) ] with 1 more call #> 40. seplyr::select_nse(data.frame(x = 1, z = 3), -y) #> 41. seplyr::select_se(.data, colNames) #> 43. dplyr:::select.data.frame(.data, !!!colSyms) #> 44. tidyselect::eval_select(expr(c(...)), .data) #> 45. tidyselect:::eval_select_impl(...) #> 53. tidyselect:::vars_select_eval(...) #> 54. tidyselect:::walk_data_tree(expr, data_mask, context_mask) #> 55. tidyselect:::eval_c(expr, data_mask, context_mask) #> 56. tidyselect:::reduce_sels(node, data_mask, context_mask, init = init) #> 57. tidyselect:::walk_data_tree(new, data_mask, context_mask) #> 58. tidyselect:::as_indices_sel_impl(...) #> 59. tidyselect:::as_indices_impl(x, vars, strict = strict) #> 60. tidyselect:::chr_as_locations(x, vars) #> 61. vctrs::vec_as_location(x, n = length(vars), names = vars) #> 63. vctrs:::stop_subscript_oob(...) #> 64. vctrs:::stop_subscript(...)