r - 并行运行 `pbapply` 不允许在环境之外写入
问题描述
请参阅下面的虚拟代码。如果我删除参数,该pblapply()
函数将写入。x1
cl = 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)
解决方案
推荐阅读
- arrays - TypeScript 不能使用数组原型
- teamcity - 如何在 Teamcity 中获取 Gatling 报告
- c++ - 如何将结构的char数组复制到结构的另一个char数组中?
- reactjs - 反应实例变量未定义
- firebase - Firebase Firestore https 可调用云函数中出现未经验证的错误
- jenkins - 詹金斯不以全尺寸打开浏览器窗口
- javascript - 将对象中的内容添加到 JQUERY-CONFIRM
- html - Bootstrap 4 - col 中的固定底部消息框(类似松弛的界面)
- javascript - 选择 createElement JS 创建的标签
- python - 落在网格网格之外的数据点被插值,而网格网格肯定覆盖了这些点