bcgov / bcgroundwater

An R package to facilitate analysis and visualization of groundwater data from the British Columbia groundwater observation well network
Apache License 2.0
20 stars 4 forks source link

Avoid global variables #1

Closed ateucher closed 6 years ago

ateucher commented 9 years ago

Refactor dplyr and ggplot code using standard evaluation "escape hatches"

steffilazerte commented 6 years ago

So far I've addressed this by:

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:

ateucher commented 6 years ago

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:.

steffilazerte commented 6 years ago

Fixed: 8787364