Skip to content
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

eval_select names validation depends on type of expr #346

Open
eutwt opened this issue Nov 19, 2023 · 0 comments
Open

eval_select names validation depends on type of expr #346

eutwt opened this issue Nov 19, 2023 · 0 comments

Comments

@eutwt
Copy link
Contributor

eutwt commented Nov 19, 2023

If expr is character, it appears to not check for duplicate names

df <- setNames(data.frame(x = 1, x = 1), c("x", "x"))
tidyselect::eval_select('x', df)
#> x 
#> 1
tidyselect::eval_select(as.symbol('x'), df)
#> Error:
#> ! Names must be unique.
#> ✖ These names are duplicated:
#>   * "x" at locations 1 and 2.
#> Backtrace:
#>      ▆
#>   1. └─tidyselect::eval_select(as.symbol("x"), df)
#>   2.   └─tidyselect:::eval_select_impl(...)
#>   3.     ├─tidyselect:::with_subscript_errors(...)
#>   4.     │ └─base::withCallingHandlers(...)
#>   5.     └─tidyselect:::vars_select_eval(...)
#>   6.       └─tidyselect:::ensure_named(...)
#>   7.         └─vctrs::vec_as_names(names(pos), repair = "check_unique", call = call)
#>   8.           └─vctrs (local) `<fn>`()
#>   9.             └─vctrs:::validate_unique(names = names, arg = arg, call = call)
#>  10.               └─vctrs:::stop_names_must_be_unique(names, arg, call = call)
#>  11.                 └─vctrs:::stop_names(...)
#>  12.                   └─vctrs:::stop_vctrs(...)
#>  13.                     └─rlang::abort(message, class = c(class, "vctrs_error"), ..., call = call)

Created on 2023-11-18 with reprex v2.0.2

This carries through to dplyr::select()

df <- setNames(data.frame(x = 1, x = 1), c("x", "x"))
dplyr::select(df, 'x')
#>   x
#> 1 1
dplyr::select(df, x)
#> Error in `dplyr::select()`:
#> ! Names must be unique.
#> ✖ These names are duplicated:
#>   * "x" at locations 1 and 2.
#> Backtrace:
#>      ▆
#>   1. ├─dplyr::select(df, x)
#>   2. └─dplyr:::select.data.frame(df, x)
#>   3.   └─tidyselect::eval_select(expr(c(...)), data = .data, error_call = error_call)
#>   4.     └─tidyselect:::eval_select_impl(...)
#>   5.       ├─tidyselect:::with_subscript_errors(...)
#>   6.       │ └─base::withCallingHandlers(...)
#>   7.       └─tidyselect:::vars_select_eval(...)
#>   8.         └─tidyselect:::ensure_named(...)
#>   9.           └─vctrs::vec_as_names(names(pos), repair = "check_unique", call = call)
#>  10.             └─vctrs (local) `<fn>`()
#>  11.               └─vctrs:::validate_unique(names = names, arg = arg, call = call)
#>  12.                 └─vctrs:::stop_names_must_be_unique(names, arg, call = call)
#>  13.                   └─vctrs:::stop_names(...)
#>  14.                     └─vctrs:::stop_vctrs(...)
#>  15.                       └─rlang::abort(message, class = c(class, "vctrs_error"), ..., call = call)

Created on 2023-11-18 with reprex v2.0.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant