Calling functions from non-base R packages in `parallel` package without librarying them within the function

parallel-processing, r

Solution

I don't see any `combinations` function in gregmisc. Could that be your actual problem?

Loading packages on each node with `clusterEvalQ()` should work, and always has worked for me. The following code is lifted nearly verbatim from page 8 of `vignette("parallel")`:

require(parallel)
cl <- makeCluster(4)
junk <- clusterEvalQ(cl, library(boot)) ## Discard result

Problem

Lets say I'm trying to run the following code ``` library(gregmisc) library(parallel) myfunction <- function(x){ combinations(10, x, 1:10) } cl <- makeCluster(getOption("cl.cores", 2)) parLapply(cl, 3, myfunction) ``` I'm getting the error ``` #Error in checkForRemoteErrors(val) : #one node produced an error: could not find function "combinations" ``` So if I'll library "gregmisc" package within the function it will work ``` myfunction <- function(x){ library(gregmisc) combinations(10, x, 1:10) } cl <- makeCluster(getOption("cl.cores", 2)) parLapply(cl, 3, myfunction) ``` The question is, how can I avoide librarying packages within the function? I saw similar questions were asked already re "snow" and "snowfall" in here and here but I couldn't get it to work for the "parallel" package I've tried (without success) ``` library(snow) library(snowfall) sfExport(list=list("combinations")) sfLibrary(gregmisc) clusterEvalQ(cl, library(gregmisc)) ```

Original source

Related problems