当mclapply(X, FUN)
遇到 的某些值的错误时X
,错误会传播到 的其他一些(但不是全部)值X
:
require(parallel)
test <- function(x) if(x == 3) stop() else x
mclapply(1:3, test, mc.cores = 2)
#[[1]]
#[1] "Error in FUN(c(1L, 3L)[[2L]], ...[cut]
#
#[[2]]
#[1] 2
#
#[[3]]
#[1] "Error in FUN(c(1L, 3L)[[2L]], ... [cut]
#Warning message:
#In mclapply(1:3, test, mc.cores = 2) :
# scheduled core 1 encountered error in user code, all values of the job will be affected
我怎样才能阻止这种情况发生?