Reputation: 1279
I have created a function DevCstat().
It takes the arguments: indat, mod, Covar,txtMat, PatCovar.
indat is a list, I would like to apply the function to each element of the list.
mod, Covar, txtMat, PatCovar, are objects that I would like to use for each call to the function, these do not change over the list elements.
This seems to work:
lapply(test, DevCstat, mod='A', Covar=Covar,txtMat=txtMat, PatCovar=PatCovar)
However, the parallel version does not work:
mclapply(test,DevCstat,mod = 'A', Covar=Covar, txtMat=txtMat, PatCovar=PatCovar, SIMPLIFY = F, mc.cores = getOption("mc.cores", numcore))
I get the error
all scheduled cores encountered errors in the user code
I think the problem is that mclapply is not passing the additional arguments.
Does anyone know how to correctly do this?
Thanks
Upvotes: 5
Views: 4958
Reputation: 19677
You can see from the following example that mclapply
does allow extra arguments in this way:
mclapply(2:4, function(i,j,k) c(i,j,k), i=1, k=5)
I think your problem is that mclapply
doesn't take a SIMPLIFY
argument, so it passes it on to your function causing the error. You might be getting confused with mcmapply
, which does take a SIMPLIFY
argument.
Upvotes: 9