0

i have a comparable issue like already discussed here: No visible binding for global variable Note in R CMD check

In my case, I am using the function ddply in my own package and when I check the R-package I get a note that there is "no visible binding for global variable 'VARX'.

The adressed code line is:

subsample <- ddply(my_data, .(VARX), function(x){x[sample(nrow(x), 1), ]})

The variable VARX is a column in a dataframe that is provided by the package (sysdata). What is good practice to improve that code for a proper R-package?

Community
  • 1
  • 1
Johannes
  • 1,024
  • 13
  • 32

1 Answers1

5

The problem has nothing to do with ddply, it is just that VARX is not a valid object in the current workspace as it is a column in my_data. The suggestions in the question you linked also hold here, probably placing VARX = NULL somewhere before your call to subsample <- ddply(my_data, .(VARX), function(x){x[sample(nrow(x), 1), ]}) will solve this problem as now R CMD CHECK sees that there is a VARX object. This also does not interfere with the call to ddply as scoping ensures that the VARX in my_data is used, and not the VARX in the global scope.

Paul Hiemstra
  • 59,984
  • 12
  • 142
  • 149