[R] R CMD check and foreach code

Jannis bt_jannis at yahoo.de
Thu Mar 27 15:29:24 CET 2014


Dear R users,


I have created a package and would like to check it for CRAN/R-Forge 
submission. I use some parallelized code with the help of foreach and doMC.

R CMD check now gives me a warning even though my code is correctly 
programmed (at least I think that it is). The following dummy function 
inside a package produces the error:


dummy = function() {


dummyfun = function(iter) {
iter * 2
}
registerDoMC(4)
results = foreach(i = 1:10) %dopar% dummyfun(iter = i)
}


R CMD check --as-cran mypackage

now gives:

dummy: no visible binding for global variable ‘i’


It is clear that i can not be found as only the call to foreach creates 
it (similar to a for loop), but should not the R check consider this? Or 
is my programming poor? Setting i to any arbitrary value before running 
foreach makes the error disappear, but this would feel as a really dirty 
hack.


Cheers
Jannis



More information about the R-help mailing list