4
votes

I am trying to use parLapply again (now successfully used it in this context) but this time the function to parallelize contains some functions from the mc2d package (ie. deprt, ppert). I installed and loaded the package, before the parallel part of the code.

I successfully exported my variables to the cluster using cluster export,

clusterExport(C1, "variable")
...

However I tried to export the functions dpert and ppert using

clusterEvalQ(C1,dpert)

and I get the error

object C1 not found

how does it not find C1? is there another way to export R-packages functions to the cluster for parallel processing?

2

2 Answers

7
votes

Use clusterExport for functions as well...

clusterExport(Cl,c('dpert','variable'))
0
votes

Another way I accidentally discovered is to add the name of the package to which the function belongs before the function call. E.g. instead of say syms() or group_indices() you use rlang::syms() or dplyr::group_indices() inside parLapply() (or any other parallel library function).