当我遇到意外问题时,我正在尝试调试正在使用的parLapply函数:parLapply的MoreArgs参数不起作用!现在是凌晨5点,我必须疲惫不堪,错过一些真正明显而愚蠢的东西,但是我一生都看不到它是什么。无论如何,这是给我带来麻烦的最小示例:
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)
输出为:
Error in checkForRemoteErrors(val) :
3 nodes produced errors; first error: unused argument (MoreArgs = list(min = 33, max = 110))