简体   繁体   中英

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?

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM