I’m using the exec command to call R, but I don’t understand how to handle arguments. For example the following line calls R and loads a script:
exec('/bin/R --vanilla < /home/docs/R/plotTemplate.R');
Then I want to set the directory and to call a function in the R script. The folder’s name is randomNumber so I need to somehow either pass that value to the script and set the directory within the R script or to pass it as an argument to the script.
exec("setwd(/home/reports/randomNumber/")
I can’t figure out how to stitch these lines together so that it is one exec command. A better approach might be to write a bash script but I’m also not clear on how to do this either.
You probably want to write an R script and call that with the
Rscriptfront-end which is designed with these tasks in mind.If you on an OS with an x in its name, you can also try littler for R scripting.