6

While testing the code of a package with R CMD check the following NOTE appears for every variables used inside dplyr functions using non standard evaluation: " no visible binding for global variable ..." For example if I used

cars %>% mutate(speedplusone = speed +1)

R CMD check would give the NOTE:

no visible binding for global variable speed

The question of removing these notes has been asked already and there is a reply by Hadley giving the option to either rewrite calls using standard evaluation or to fake the existence of those variable with a call to globalVariables().

According to Hadley's answer, I can remove those R CMD Check notes by using standard evaluation, replacing mutate by mutate_ :

cars %>% mutate_(speedplusone = ~speed +1)

Should I rewrite all dplyr function calls in the package to avoid non standard evaluation completely?

Community
  • 1
  • 1
Paul Rougieux
  • 10,289
  • 4
  • 68
  • 110
  • 1
    For several months I tried very hard to avoid non standard evaluation in my packages (mostly because I wasn't clever enough to figure out how to make `globalVariables()` work), but it's been a massive headache. I wouldn't bother. I have found it infinitely easier just to write my functions with NSE and then go back and edit my `globalVariables` when I do my package check. – Benjamin Oct 23 '15 at 11:23
  • 1
    I would not like changing my code only because the check returns false positives (and those are only notes after all). I'd take the `globalVariables` option. – Roland Oct 23 '15 at 11:24
  • 3
    You IMO should use the `mutate_` that being said in my own packages it can be annoying and using `speed <- NULL` in the function at the begining fixes this. – Tyler Rinker Oct 23 '15 at 11:48
  • 1
    Is it *actually* safe to use the underscored versions of the functions? I thought those were deprecated and therefore couldn't be relied on to stick around. – DuckPyjamas Dec 10 '19 at 21:33

0 Answers0