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

Recommend using all_of() for looking up variables #127

Merged
merged 2 commits into from
Oct 18, 2019

Conversation

lionel-
Copy link
Member

@lionel- lionel- commented Oct 18, 2019

First step towards #76. For now this is a simple message:

vars <- letters[1:4]
vars_select(letters, vars)
#> Note: Selecting non-column variables is brittle.
#> ℹ If the data contains `vars` it will be selected instead.
#> ℹ Use `all_of(vars)` to silence this message.
#>   a   b   c   d
#> "a" "b" "c" "d"

We can move on to formally deprecating this kind of lookup in the next version.

I would like to refer to all_of() in the message, but there will be a transition period where dplyr hasn't exported the new selectors. To work around this, the second commit binds the selection helpers inside the context mask. This is what several client packages are already doing. This makes it easier to use dplyr functions without the package attached:

# Before
dplyr::select(mtcars, dplyr::starts_with("c"))

# After
dplyr::select(mtcars, starts_with("c"))

It is still recommended to export the helpers so their help topics are easily accessible.

@lionel- lionel- requested a review from hadley October 18, 2019 16:44
@lionel- lionel- merged commit 7341cbc into r-lib:master Oct 18, 2019
@lionel- lionel- deleted the add-lookup-msg branch October 18, 2019 18:06
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

Successfully merging this pull request may close these issues.

2 participants