I have a process in R that monitors a website (lets call it A). Once an event happens, I want to start up another R-script with it's own process (lets call it B). The initial R script (A) needs to pass parameters into the second script (B). The initial script needs to keep going monitoring... It might find another event and will need to start another instance of B. it is possible to have up to 10ish B-scripts running at any point in time.
When I open a CMD window and run this, it works:
Rscript.exe C:/Temp/myBscript.R parameter1, parameter2, parameter3, parameter4
but, when I run the following code in R, it does not work:
system(
paste("Rscript.exe C:/Temp/myBscript.R", parameter1, parameter2, parameter3, parameter4)
, wait=FALSE)
The wait = TRUE is there so I can start multiple B scripts and A does not wait for B to finish.
In addition, I have other scripts that I would like to run from a location with spaces in the folder name. I've tried things like:
system(
paste("\"Rscript.exe \"C:\\My Drive\\Folder with spaces in Name\\My B script with spaces.R\"", parameter1, parameter2, parameter3, parameter4 "\"\"")
, wait=FALSE)
but with no success...
EDIT: The Rstudio console just returns '0'. I know its not working, because script-B should write a file... which it does not when I run the commands above in R (but does write a file when I run the first option [directly in CMD]). Also, in Windows Task Manager I see it does not start a 'CMD task'
EDIT2:
Example script A:
parameter1 = "testPara1"
parameter2 = "InfoPart2"
system(
paste("Rscript.exe C:/Temp/myBscript.R", parameter1, parameter2)
, wait=FALSE)
Example script B (C:/Temp/myBscript.R):
args = commandArgs(trailingOnly=TRUE)
par1 = args[1]
par2 = args[2]
dd <- data.frame("parameter1" = par1,
"parameter2" = par2)
write.csv(dd, "C:\\Temp\\TestFileWithParameters.csv", row.names = FALSE)