I have a script test.R that takes arguments arg1, arg2 and outputs a arg1-arg2.csv file.
I would like to run the test.R in 6 parallel sessions (i am on a 6 core CPU) and in the background. How can I do it?
I am on linux
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You did not provide a reproducible example so I am making one up. As you are on Linux, I am also swicthing to littler which was after all writtten for the very purpose of scripting with R.
and you can then lauch this either from the command-line as I do here, or from another (shell) script. The key is the
&at the end to send it in the background:The
[$n]indicates how process how been launched in the background, the number that follows is the process id which you can use to monitor or kill. After a little while we get the results:You may want to read up on Unix shells to learn more about
&m thefgandbgbackground s etc.Lastly, all this can a) also be done with
Rscriptthough picking arguments is slightly different and b) there are CRAN packages getopt and optparse to facilitate working with command-line arguments.