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

Open
hadley opened this issue Jan 19, 2023 · 1 comment
Open

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

hadley opened this issue Jan 19, 2023 · 1 comment

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.

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