I'm using reticulate
in RMarkdown and am trying to run a locally defined Python function with parallel processing. I've looked around and this answer is the closest I've found to solving my issue except the function I'm using is not defined in a separate Python script, but rather within Rmarkdown. Below is a simplified example using llply
, which gives me the error Error in unserialize(socklist[[n]]) : error reading from connection
.
I have also tried foreach()
, which doesn't recognize the py$
object even with reticulate::py$function
.
I have also tried mclapply
and pbmcapply
, which appear to run and engage all cores, but they keep hanging and won't finish.
```{r}
library(reticulate)
library(doParallel)
library(foreach)
library(plyr)
```
```{python}
def myFn1(x):
return(sqrt(x))
```
```{r}
cl <- makeCluster(detectCores())
registerDoParallel(cl)
llply(list(2, 3, 4), .fun=reticulate::py$myFn1, .parallel=TRUE)
stopCluster(cl)
```
I am not very knowledgeable about reticulate or parallel processing and I would be really grateful for any help.