Dario Federici
Dario Federici

Reputation: 1258

R system2 run different scripts in parallel

I believe using system2() is a good option for running two R scripts in parallel. I'm trying something like the following:

Sys.time()
system2(command = 'Sys.sleep(5)', wait = FALSE)
system2('Sys.sleep(7)', wait = FALSE)
Sys.time()

However, it does not work and I'm also getting this warning:

running command '"Sys.sleep(7)"' had status 127

The documentation of system or system2 does not show any example and I can't find much around. Has anyone tried this option to solve this problem?

Upvotes: 2

Views: 337

Answers (1)

Nairolf
Nairolf

Reputation: 2556

The following works for me:

 system("Rscript -e 'Sys.sleep(5); \"task 1\"'", wait=FALSE)
 system("Rscript -e 'Sys.sleep(7); \"task 2\"'", wait=TRUE)
 [1] "task 1"
 [1] "task 2"

Version with system2() (thanks to the comment of HenrikB):

system2("Rscript", args = c("-e", "'Sys.sleep(5); \"task 1\"'"), wait=FALSE)
system2("Rscript", args = c("-e", "'Sys.sleep(7); \"task 2\"'"), wait=TRUE)
[1] "task 1"
[1] "task 2"

Upvotes: 1

Related Questions