Reputation: 1467
I am confused as to why the loginfo method from the "logging" package seemingly cannot be found when used with ddply and .parallel=TRUE.
Here is an example to highlight the problem. The example calculates the average sepal length by species using ddply. This code works as expected if .parallel=FALSE. But if .parallel=TRUE it complains that it cannot find the 'loginfo' method.
library(logging)
library(doSNOW)
registerDoSNOW(cl <- makeCluster(4, type="SOCK"))
data(iris)
ddply(iris, .(Species), function(iris) {
loginfo("now working with %s", unique(iris$Species)) # if parallel, can't find function?!
mean(iris$Sepal.Length)
}, .parallel=TRUE)
stopCluster(cl)
--
Error in do.ply(i) : task 1 failed - "could not find function "loginfo""
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, ...)’
Upvotes: 0
Views: 1076
Reputation: 1467
I needed to specifically export the library to the slaves. Thanks, Konrad.
clusterEvalQ(cl, library(logging))
Upvotes: 1