[R] Can R scripts executed in batch mode take a commandline argument?
Prof Brian Ripley
ripley at stats.ox.ac.uk
Thu Oct 16 06:26:04 CEST 2008
On Wed, 15 Oct 2008, cls59 wrote:
>
> On Unix/Linux platforms, you can use the included Rscript utility by adding
> the following shebang at the top of your program. Command line arguments can
> then be retrieved using the commandArgs function:
>
> #!/usr/bin/Rscript
>
> args <- commandArgs(trailingOnly = TRUE)
>
> args is now a character vector containing every space delimited text string
> that followed your program name when you ran it. trailingOnly is set to TRUE
> because the RScript interpreter prepends a few arguments of it's own that
> you will probably have no use for.
>
> As I stated earlier, this approach works great on Unix/Linux systems, I
> havn't tested it in a Windows environment.
There is no support for #! in the standard Windows shell. Also, you need
to make the script executable in a Unix-alike, and there's no concept of
that on Windows file systems. But the Cygwin shells have an emulation.
This is mentioned in 'An Introduction to R', the most basic R manual.
>
> Good Luck!
>
> -Charlie
>
> -----
> Charlie Sharpsteen
> Undergraduate
> Environmental Resources Engineering
> Humboldt State University
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list