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
Deprecate .data
in data-expressions
#169
Comments
Do we need an |
Out of curiosity, was the fact that this pattern has been recommended in this vignette https://dplyr.tidyverse.org/articles/programming.html for quite some time taken into account when this change was made? It seems like it's causing a lot of people to go changing a lot of code ... is it really needed? |
@dblodgett-usgs yes |
Well ok then, thanks I guess. It appears the documentation has actually changed at that vignette? I see you committed a change ~20 days ago but it only deployed to github pages two days ago. Reading that now, it does make more sense... it just seemed strange because I checked that vignette and it hadn't changed. |
I'd like to know what the best way is regarding this change when it comes to notes during R CMD check? I recently added .data$ to eliminate the (many, many) notes during package checking, but with the newest package versions, look like I need to revert back. Couldnt find it anywhere or I oversaw? Thanks! |
The warning message should tell you what to do: out <- mtcars |> dplyr::select(.data$cyl)
#> Warning: Use of .data in tidyselect expressions was deprecated in tidyselect 1.2.0.
#> ℹ Please use `"cyl"` instead of `.data$cyl` Created on 2022-12-08 with reprex v2.0.2 |
Sorry maybe I was not clear, the warning message is absolutely clear. However, when building packages, R CMD check prints the almighty famous "no visible binding for global variable" note for each instance when not using the .data$ prefix. Before this change, I found the .data$ construct to be the best to avoid this note, I didnt like defining dozens of global variables. Is there any updated recommendation on this in light of this change? |
@chrarnold -- this article was updated recently and has a pretty thorough summary of the details on this. https://dplyr.tidyverse.org/articles/programming.html#data-masking In short, use .data$foo for things that do not use tidyselect and "foo" for things that do use tidyselect. Which function is throwing the error should be a guide but for me it was basically select/rename use "foo" and filter/mutate/group_by use .data$foo. See DOI-USGS/nhdplusTools#306 for my clean up issue on this if it helps. |
@chrarnold If you use |
Thanks @lionel- and @dblodgett-usgs , I didnt know @dblodgett-usgs In a tidyselect context, wouldnt the R CMD check notes still be there then? I really want to get rid of these notes, having hundreds of them bloats up the output so much |
This was also supported in old versions of dplyr.
No because in tidyselect contexts you now use quoted names like |
Thanks, I have not read the "new" quoted recommendation anywhere else to be honest, also not in the quoted (and updated) https://dplyr.tidyverse.org/articles/programming.html#data-masking article. I'll update my code correspondingly! |
@chrarnold To be clear, in data-masking (as in the link you just shared), a string represents a string, not a column. So you can't do things like It's only for column selection that you can refer to a column with a string. |
@lionel- Then what is the recommended way to replace |
It's only been deprecated in tidy selections, e.g. in contexts like |
Based on new version of tidyselect, see r-lib/tidyselect#169
* Remove use of .data$account_id in selection and arranging of data frames in transaction function. * Use data masking in `dplyr::arrange()` and so change to `dplyr::arrange(.data[["account_id"]])`. This eliminates global variable warnings and avoids `arrange()` not working with quoted variable. * Use quoted variable of "account_id" with `dplyr::select()`. * Move use of `arrange(account_id)` to end of function so it is only written once, not for each possible outcome. * Fixes tidyselect issue 169: r-lib/tidyselect#169
To make programming with data-masking and programming with selections completely distinct.
The text was updated successfully, but these errors were encountered: