I am trying to create a package and using dplyr throughout. When I do devtools::check(), I get some warnings related to the column names in the dplyr functions. To resolve this, I appended .$ in front of the column names. The error related to the column names went away but now I get the following warning when I run devtools::check(). Is there any way to fix this warning?
We can fix that ambiguity by being more explicit and using the .data pronoun. This will throw an informative error if the variable doesn’t exist:
mutate_y <- function(df) {
mutate(df, y = .data$a + .data$x)
}
mutate_y(df1)
#> Column `a` not found in `.data`
If this function is in a package, using .data also prevents R CMD check from giving a NOTE about undefined global variables (provided that you’ve also imported rlang::.data with @importFrom rlang .data ).