Cannot load library data.table to R parallel

2019-07-28 21:00发布

R throws an error when I use the below code to load library data.table to the cpu cluster. But data.table package is installed on R and it's working fine when used outside parallel code.

no_cores <- detectCores() - 1
cl <- makeCluster(no_cores,outfile="out.txt")
clusterEvalQ(cl, library(data.table))

Error :-

clusterEvalQ(cl, library(data.table)) Error in checkForRemoteErrors(lapply(cl, recvResult)) : 3 nodes produced errors; first error: there is no package called 'data.table'

1条回答
Explosion°爆炸
2楼-- · 2019-07-28 21:41

Building on what HenrikB said above in the comments, I got rid of this problem by adding my .libPaths() call to clusterEvalQ():

.libPaths("C:/programs/rlib")
library(parallel)
no_cores<-detectCores()-1

cl<-makeCluster(no_cores)
#this is needed to see the package
clusterEvalQ(cl, .libPaths("C:/programs/rlib"))

# I'm using a function that uses the stringdist library
clusterEvalQ(cl, library(stringdist))

#You need to load your data into the cluster also
clusterExport(cl, "unmatched")
clusterExport(cl, "matched")

#now we're going to run it, amatch is a function in the stringdist lib

parLapply(cl, unmatched,function(x) amatch(x,matched, maxDist = Inf))
查看更多
登录 后发表回答