R中的mclapply:找不到对象'X'

时间:2016-02-26 17:11:55

标签: r parallel-processing lapply mclapply

我正在尝试使用并行软件包中的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.

知道发生了什么事吗?提前谢谢!

0 个答案:

没有答案