user3642360
user3642360

Reputation: 792

Run two different R scripts at a time on windows

I have two R scripts. one is: source("D:/source_code_CCA.r") and another one is: source("D:/source_code_DL.r"). These two R scripts are completely independent. I want to run these two r scripts at a time on same R console on windows. How can I do this? Please help!

Upvotes: 3

Views: 1340

Answers (2)

Jason V
Jason V

Reputation: 1147

You could create a new script containing the following lines, or execute them via interactive console -- after making sure that the directory containing Rscript.exe is in your PATH:

shell(cmd = 'Rscript.exe D:/source_code_cca.r', wait=FALSE)
shell(cmd = 'Rscript.exe D:/source_code_DL.r', wait=FALSE)

(If it's not already there, the value to add to path could be C:\Program Files\R\R-3.1.2\bin or C:\Program Files\R\R-3.1.2\bin\x64)

Note that if you use cats or messages, those would be captured if you direct them to a text file, such as in:

shell(cmd = 'Rscript.exe D:/source_code_cca.r > out1.log', wait=FALSE)
shell(cmd = 'Rscript.exe D:/source_code_DL.r > out2.log', wait=FALSE)

Or if you specify intern=TRUE and assign the function's result to some variable:

res1 <- shell(cmd = 'Rscript.exe D:/source_code_cca.r', wait=FALSE, intern=TRUE)
res2 <- shell(cmd = 'Rscript.exe D:/source_code_DL.r', wait=FALSE, intern=TRUE)

Upvotes: 2

rlegendi
rlegendi

Reputation: 10606

I believe you're using Windows, the path tells me :-)

  1. Open two different cmd.exe windows.
  2. Use the R command to call one of the script in the first window, and one for the second. This can be done with some minor magic like: R.exe --no-environ --no-save > "out.txt"

Hope that helps. Alternatively, you can spawn different processed if you want to call them within the same shell.

Upvotes: 0

Related Questions