[R] R CMD check and foreach code
Jannis
bt_jannis at yahoo.de
Thu Mar 27 17:46:18 CET 2014
On 27.03.2014 15:58, Duncan Murdoch wrote:
> I would use a slightly less dirty hack: call globalVariables() to
> declare that i is global.
>
> The foreach() function is using nonstandard evaluation to make this
> work, and codetools (that does the checks) doesn't know all the ins
> and outs of it. (foreach is in a contributed package, not base R.)
> The globalVariables() function is a way to tell codetools that even
> though it looks wrong, the variable is really being used safely.
>
> Duncan Murdoch
>
Thanks, Duncan, for your reply. So how would I use this now? Reading the
documentation still leaves me puzzled .... Just adding
globalVariables('i') to the dummy function like this:
dummy = function() {
globalVariables('i')
dummyfun = function(iter) {
iter * 2
}
registerDoMC(4)
results = foreach(i = 1:10) %dopar% dummyfun(iter = i)
}
does not solve the problem.
Cheers
Jannis
More information about the R-help
mailing list