2

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?

2
  • Parameter command expects a system command, not an R command. Commented Oct 26, 2018 at 6:38
  • The R package future CRAN.R-project.org/package=future can be used to evaluate expressions in parallel. Commented Oct 26, 2018 at 20:23

1 Answer 1

1

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

1 Comment

The first argument to system2() must be an executable, so you want to use system2("Rscript", args = c("-e", "'Sys.sleep(5); \"task 1\"'"), ...) in the latter case.

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.