views:

54

answers:

1

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:

eg. 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?

Thanks a lot,

ExtremeCoder


Although unrelated I would also like to know how do I plot a line of best fit in R for a certain table of data?

+2  A: 
  1. You want Rscript.exe.

  2. You can control the output from within the script -- see sink() and its documentation.

  3. You can access command-arguments via commandArgs().

  4. You can control command-line arguments more finely via the getopt and optparse packages.

  5. If everything else fails, consider reading the manuals or contributed documentation

Dirk Eddelbuettel