foreach
foreach copied to clipboard
foreach in packages and tests
Hi, actually I can't found doc, to how use this package in tests, seems it does not works very well with rcmdcheck.
foreach::foreach(x = iterators::iter(matrix, by = "col"), .combine = 'cbind', .packages = 'dplyr') %dopar% {
x
}
Then the message:
❯ checking R code for possible problems ... NOTE
Undefined global functions or variables:
x
We can use globalVariables(), but is a very bad idea, can even hide problems, I notice there is tests in this package and rcmdcheck works!, I would like to know how to use this package in packages, and ideally add the data to the docs plis.
Thx!
FWIW, you can do:
y <- foreach::foreach(x = 1:3) %dopar% {
## To please 'R CMD check'
x <- x
sqrt(x)
}
That tricks codetools to not "see" x as a global variable. Note, however, it could be that one day this trick won't work anymore.
Alternatively, you can do:
## To please 'R CMD check'
x <- NULL
y <- foreach::foreach(x = 1:3) %dopar% {
sqrt(x)
}
Great!, working even now :3
Maybe add this to the doc (?