并行使用时data.table失败

时间:2014-03-31 12:57:22

标签: r data.table

我想在一个名为via plyr的函数中并行使用data.table。

以下代码使用data.table 1.9.2和R 2.15.3 但没有data.table 1.9.3和R 3.0.3

在R 3.0.3中,仅当并行= F

关闭并行化时,它才有效

我得到的错误是

> Error in do.ply(i) :    task 1 failed - "Check that is.data.table(DT)
> == TRUE. Otherwise, := and `:=`(...) are defined for use in j, once only and in particular ways. See help(":=")." In addition: Warning
> messages: 1: <anonymous>: ... may be used in an incorrect context:
> ‘.fun(piece, ...)’   2: <anonymous>: ... may be used in an incorrect
> context: ‘.fun(piece, ...)’

在R 3.0.3中重现错误消息的代码是:

library(doSNOW) 
cl<<-makeCluster(2)  
registerDoSNOW(cl)

library(plyr)

myfun=function(x){
  library(data.table)
  mydt=data.table(a=1:12)
  mydt[,b:=a*2]
  mydt

}
gg=ldply(1:2,.fun=myfun,.parallel=T)
stopCluster(cl)

0 个答案:

没有答案