Reputation: 792
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
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 cat
s or message
s, 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
Reputation: 10606
I believe you're using Windows, the path tells me :-)
cmd.exe
windows.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