首页 > 解决方案 > 并行运行 `pbapply` 不允许在环境之外写入

问题描述

请参阅下面的虚拟代码。如果我删除参数,该pblapply()函数将写入。x1cl = cores

有没有办法强制这样做?

input <- c(1,2,3)
myfunc <- function(input) {
  x1 <- list()
  cores <- parallel::makeCluster(2)
  x2 <- unlist(pbapply::pblapply(cl = cores,
                                   input,
                                   function(i) {
                                     x1[[i]] <<- i+3
                                     return(i)
                                   }
  ))
  return(c(x1,x2))
}
myfunc(input)

标签: rparallel-processing

解决方案


推荐阅读