Closed ateucher closed 6 years ago
So far I've addressed this by:
aes_string()
in ggplot2 function calls.data$variable
notation in tidyverse function calls (i.e. mutate
, group_by
, etc)Using .data$variable
avoids the possibility of accidentally using a variable in the global environment but it still results in one undeclared global variable: .data
The only other way (that I've found) to avoid global variables entirely is to use the rlang
package, for example:
g %>%
dplyr::group_by(rlang::UQS(rlang::parse_expr("Well_Num")))
This seems overly cumbersome and requires another package. It's entirely possible there's an easier way, but I haven't been able to figure it out, as of yet.
I would suggest either:
globalVariables()
function to declare all NSE variables we use (removes Notes from the output of check).data
and aes_string
and be satisfied with one undeclared global variable (.data
) [Currently implemented]That's great! Yeah, I think the rlang
way is the new way to do things, but I think since these in general are not user-supplied variables (they are column names that must be in the data, correct?) the .data
approach seems entirely reasonable. I also noticed here that you can use @importFrom rlang .data
to avoid .data being identified as a global variable. (And dplyr
already imports rlang
, so I'm not too worried about adding it to our Imports:
.
Fixed: 8787364
Refactor dplyr and ggplot code using standard evaluation "escape hatches"