I have some R code inside a file called analyse.r. I would like to be able to, from the command line (CMD), run the code in that file without having to pass through the R terminal and I would also like to be able to pass parameters and use those parameters in my code, something like the following pseudocode:
C:\>(execute r script) analyse.r C:\file.txt
and this would execute the script and pass “C:\file.txt” as a parameter to the script and then it could use it to do some further processing on it.
How do I accomplish this?
You want
Rscript.exe.You can control the output from within the script — see
sink()and its documentation.You can access command-arguments via
commandArgs().You can control command-line arguments more finely via the getopt and optparse packages.
If everything else fails, consider reading the manuals or contributed documentation