1
votes

I have five R scripts in a folder, and I would like to run all these R scripts in parallel, controlling the number of cores available.

What do you suggest to do? I tried to use "foreach" package in this way but it didn't work.

files<-list.files(pattern=".R")

foreach(x=files) %dopar% {
        source(x)
      }
1

1 Answers

0
votes

Did you register a parallel backend? If it is a single system then use doParallel package to register the backend first. Try this;

cl = makeCluster(detectCores() - 1)
registerDoParallel(cl)

files<-list.files(pattern=".R")

foreach (i in 1:length(files), .export = c("files")) %dopar%
 {
 source(files[i])
 }

stopCluster(cl)