devtools::check giving error on dplyr column names

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?

 Undefined global functions or variables:


1 Like

I believe the solution is to use the .data pronoun imported from rlang with @importFrom rlang .data.

From the dplyr Programming vignette:

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)

#> 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 with @importFrom rlang .data ).


Thank you very much. That worked like a charm.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.