1

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 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

1 Comment

What was the error or issue? you Had installed doparallel package right?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.