R parallel rbindlist not working

I have a function that uses rbindlist, and I would like to call this function using parLapply. Simplified version below:

func <- function(x){
  df1 <- data.frame(a = c(x,2), b = c(3,4))
  df2 <- data.frame(a = c(x,2), b = c(4,4))
  rbindlist(list(df1,df2))
}

cl <- makeCluster(getOption('cl.cores', detectCores()))
tmp <- parLapply(cl,c(1,2),func)
stopCluster(cl)

However, I get the error message:

Error in checkForRemoteErrors (val): 2 nodes caused errors; first error: could not find function "rbindlist"

+4
source share
1 answer

If using other libraries with, parlapplymake sure that you loaded them correctly on each node. You can do

clusterEvalQ(cl, library(data.table))

Before running your commands or enable

require(data.table)

in your function.

+3
source

Source: https://habr.com/ru/post/1544614/


All Articles