R simultaneously starts two different code blocks (in parallel)

Is there a way to run two different blocks of code at the same time. I looked at parallel packages inside R, and all of them seem to be based on running the same function in a loop. I am looking for a way to simultaneously run various functions (1 loop iteration). For example, I would like to create a model on a specific data object at the same time as creating another model on another object. I could do this by running another instance of R, but would rather save it all in the same script. Is it possible? I appreciate any advice.

+3
source share
2 answers

You can try to substitute / quote functions, then evaluate them in parallel.

library(parallel)
ExpressionVect <- c(substitute(function1()), 
                substitute(function2()))

mclapply(ExpressionVect, eval, mc.cores= 2)

,

+2

clusterMap, mapply. , node (lm, glm, rpart, ).

clus <- makeCluster(2)
out <- clusterMap(clus, lm, formula=list(speed ~ dist, mpg ~ cyl + disp + hp),
                            data=list(cars, mtcars))
0

All Articles