我正在尝试使用并行包中的 mclapply(在 Mac 上)并且遇到了问题。我将函数 edge.loop 定义为:
edge.loop <- function(index) {
hw.edge <- E(G)[HW.edges][index]
apath <- E(G)$emig.route[[hw.edge]]
short.cut <- apath[is.in.graph(G, apath, what="edges")]
Edata <- get.data.frame(G, what="edges")
lag.surv <- 1; # initialize
x.surv <- 1
result_list <- vector("list",length(short.cut))
for (x in short.cut) {
if ( E(G)[x]$cum.path.surv == -1 ) {
if ( E(G)[x]$int.dam.type!=0 ) {
x.surv <- 0
if (E(G)[x]$up.passage==1) {
x.surv <- lag.surv*E(G)[x]$Sentrain*S.Impinge
}
result_list[x] <- x.surv
lag.surv <- x.surv
}
}
else lag.surv <- E(G)[x]$cum.path.surv
}
return(list("short.cut" = short.cut, "x.surv" = result_list))
}
当我将此函数称为
x <- edge.loop(1)
它工作得很好,但如果我尝试
x <- lapply(1:2, edge.loop)
或者
x <- mclapply(1:2, edge.loop)
我收到错误读数
Error during wrapup: object 'X' not found.
知道发生了什么吗?提前致谢!