I was trying to debug a parLapply function that I am working on when I encountered an unexpected problem: the MoreArgs argument to parLapply is not working! It's 5AM at the moment, and I must be fatigued and missing something really obvious and silly, but I cannot for the life of me see what it is. Anyway, here is the minimal example that is giving me trouble:
require(parallel)
cluster <- makeCluster(3)
testFUN <- function(n=10, min=0, max=100, outname="test1.Rdata"){
nums <- runif(n, min=min, max=max)
total <- sum(nums)
save(total, file = outname)
return(total)
}
#just to make sure the function works
testFUN(n=5, min=4, max=150, outname = "test0.Rdata")
#make sure the cluster can get the functions
clusterExport(cluster, list("testFUN", "runif", "sum", "save"))
nlist <- list(first=5, second=10, third=15)
parLapply(cl = cluster, nlist, testFUN, outname=c("test1.Rdata", "test2.Rdata", "test3.Rdata"), MoreArgs=list(min=33, max=110))
stopCluster(cluster)
and the output was:
Error in checkForRemoteErrors(val) :
3 nodes produced errors; first error: unused argument (MoreArgs = list(min = 33, max = 110))