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

any_of() fails with function name clash #354

Closed
mb147 opened this issue Jul 22, 2024 · 1 comment
Closed

any_of() fails with function name clash #354

mb147 opened this issue Jul 22, 2024 · 1 comment

Comments

@mb147
Copy link

mb147 commented Jul 22, 2024

I happened to use a variable 'matches', and it gave this tricky to understand error from function name clash within the tidyselect package.

Doesn't have to be 'matches'; also tested with 'contains'.
Using a variable name of a function outside of tidyselect package seems to be fine (e.g. 'hasName').

Expected behaviour would be to detect the user has a variable in calling environment and point to that instead of function in package.

reprex:

my_select <- \(x, expr) tidyselect::eval_select(rlang::enquo(expr), x)

df <- data.frame(name = "foo", value = "bar")
matches <- c("name")
will_error <- my_select(df, tidyselect::any_of(matches))
#> Error in `my_select()`:
#> ℹ In argument: `tidyselect::any_of(matches)`.
#> Caused by error in `tidyselect::any_of()`:
#> ! Can't subset elements.
#> ✖ Subscript must be numeric or character, not a function.

version$version.string
#> [1] "R version 4.3.2 (2023-10-31 ucrt)"
packageVersion("tidyselect")
#> [1] '1.2.1'
packageVersion("rlang")
#> [1] '1.1.4'
@lionel-
Copy link
Member

lionel- commented Oct 24, 2024

Unfortunately these name clashes are a consequence of our design decision to make the tidyselect helpers available in all contexts without having to type tidyselect::. I agree it's confusing but there's no straightforward way to improve this I can think of.

@lionel- lionel- closed this as not planned Won't fix, can't repro, duplicate, stale Oct 24, 2024
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

2 participants