The following code produces the warning:
Warning message:
<anonymous> : <anonymous>: ... may be used in an incorrect context: ‘mean(x[l], ...)’
doForeach <- function(x, ...)
{
require(doSNOW)
require(foreach)
cl <- snow::makeCluster(2, type="MPI")
on.exit(snow::stopCluster(cl))
registerDoSNOW(cl)
do.i <- function(i) lapply(seq_len(length(x)), function(l) mean(x[l], ...))
foreach(i=seq_len(10)) %dopar% { do.i(i) }
}
x <- rnorm(20)
r <- doForeach(x, trim=1)
I’d guess that it comes from the fact that the workers/slaves do not see the ... anymore. Formal arguments are typically passed as character vectors via .export=c("<arg>"), but that does not seem to work for ... arguments.
What’s the correct way of dealing with ... arguments in this example?
Okay, apparently the
...arguments have to be passed viado.i. Here is a more obvious (and correctly running) example: