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

Include examples of named any_of()/all_of() #333

Closed
hadley opened this issue Jan 19, 2023 · 2 comments
Closed

Include examples of named any_of()/all_of() #333

hadley opened this issue Jan 19, 2023 · 2 comments

Comments

@hadley
Copy link
Member

hadley commented Jan 19, 2023

tidyverse/dplyr#6644

@mike-duran-mitchell
Copy link

First of all, I absolutely appreciate that these examples were added because debugging a large script with the .groups message is pure hell without it explicitly showing where it occurred. More examples for deprecations or warnings like this, please!!! Additionally, it'd be nice to make this example a little more clear. For example, my code is:

cols_to_select <- c('col1', 'col2', col3')
subset_df <- df %>% select(-cols_to_select)

But the warning message doesn't indicate where the - sign goes. My suggestion would be just to add it in below so that it's in front of all_of() in the below example when the deprecation warning is thrown. Not really the hardest curveball for me to knock out of the park, but I can imagine newer users would feel a little confused about whether to stick the - inside or outside of all_of().

Warning message:
Using an external vector in selections was deprecated in tidyselect 1.1.0.
ℹ Please use `all_of()` or `any_of()` instead.
  # Was:
  data %>% select(cols_to_select)

  # Now:
  data %>% select(all_of(cols_to_select))

See <https://tidyselect.r-lib.org/reference/faq-external-vector.html>.
This warning is displayed once every 8 hours.
Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated. 

I got it right the first time using select(-all_of(cols_to_select)) but I also wanted to confirm the function is not agnostic regarding the placement of - and it does throw an error:

Error in `dplyr::select()`:
! Problem while evaluating `all_of(-cols_to_select)`.
Caused by error in `-cols_to_select`:
! invalid argument to unary operator
Run `rlang::last_trace()` to see where the error occurred.

laplasi added a commit to laplasi/tidyselect that referenced this issue Aug 30, 2024
`all_of()` and `any_of()` have special behaviour when `x` is a named vector. See r-lib#333. 

(First commit to a project)
@lionel-
Copy link
Member

lionel- commented Oct 24, 2024

Closed by #356.

@lionel- lionel- closed this as completed 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

3 participants