On 27/03/2014 12:46 PM, Jannis wrote:
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.
The call needs to be at the global level, i.e. outside the function.
Duncan Murdoch
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.