Dear R experts:
I am a bit stymied by how the argument picking-off works in R batch file usage.
$ cat commandArgs.R
cat(" Command Line Arguments were ", commandArgs(), "\n");
$ /usr/bin/R CMD BATCH commandArgs.R --args 1 2 3
$ /usr/bin/R --args 1 CMD BATCH commandArgs.R
... I am now getting into interactive mode ?! I guess it really is skipping the
rest of the command line
$ /usr/bin/R CMD BATCH commandArgs.R --args 1
$ ls -lt | head
total 1628148
-rw-rw-r-- 1 ivo ivo 827 Mar 31 21:47 --args
...
Could someone please let me know?
[also, are there multi-core versions of R? my guess is no, but since
I have a second processor lying around, I am trying to get it into the
fray.]
A working example would be appreciated.
regards,
/ivo welch
On Sat, 31 Mar 2007, ivo welch wrote:> Dear R experts: > > I am a bit stymied by how the argument picking-off works in R batch file > usage.You seem to mean 'R CMD BATCH' usage (there are other ways to run R in batch), and also I will assume you are talking only about a Unix-alike (these things are somewhat different on Windows). Please do follow the R posting guide and provide basic information (and read the help). In R 2.5.0 you probably want to use 'Rscript' instead for this sort of batch usage.> $ cat commandArgs.R > cat(" Command Line Arguments were ", commandArgs(), "\n");We don't want the trailing ';': this is R not C.> $ /usr/bin/R CMD BATCH commandArgs.R --args 1 2 3 > > $ /usr/bin/R --args 1 CMD BATCH commandArgs.R > ... I am now getting into interactive mode ?! I guess it really is > skipping the rest of the command lineYes, that is what --args is documented to do, skip the rest of the command line. Try R --help> $ /usr/bin/R CMD BATCH commandArgs.R --args 1 > > $ ls -lt | head > total 1628148 > -rw-rw-r-- 1 ivo ivo 827 Mar 31 21:47 --args > ...Please DO read the help here: gannet% R CMD BATCH --help Usage: R CMD BATCH [options] infile [outfile] so you have 'options' in the wrong place, and --args is matching 'outfile'. As is says that only arguments starting with '-' are considered to be options, you cannot use '1' here as an option. What you can do is R CMD BATCH '--args 1' commandArgs.R Once again, this is doing what it is documented to do.> Could someone please let me know? > > [also, are there multi-core versions of R? my guess is no, but since > I have a second processor lying around, I am trying to get it into the > fray.] > > A working example would be appreciated.R is not multithreaded, but you can make use of multithreaded BLASes: see the R-admin installation manual. -- 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
Ivo,
For R 'shell scripts', esp. on Unixy system (incl OS X), our littler
frontend
can be of help. See
http://dirk.eddelbuettel.com/code/littler.html
or
http://biostat.mc.vanderbilt.edu/LittleR
as well as the SVN archive
svn checkout http://littler.googlecode.com/svn/trunk/ littler
Using littler scripts, you can then do things like
edd at basebud:~/src/debian/Misc/svn/littler> head -20 examples/pace.r
#!/usr/bin/env r
#
# a simple example to convert miles and times into a pace
# where the convention is that we write e.g. 37 min 15 secs
# as 37.15 -- so a call 'pace.r 4.5 37.15' yields a pace of
# 8.1667, ie 8 mins 16.67 secs per mile
if (is.null(argv) | length(argv)!=2) {
cat("Usage: pace.r miles time\n")
q()
}
dig <- 5
rundist <- as.numeric(argv[1])
runtime <- as.numeric(argv[2])
[...]
which, while not as direct as getopt in bash or C, allows you to pick
arguments off the command-line. E.g.
edd at basebud:~> pace.r 3 25
Miles : 3
Time : 25
Pace : 8 min 20 sec
edd at basebud:~>
I use littler as a command-line frontend to most of my (batch) R work for
simulation or recurring data analysis.
As Prof Ripley noted. R 2.5.0 will give you something similar via Rscript.
Hth, Dirk
--
Hell, there are no rules here - we're trying to accomplish something.
-- Thomas A. Edison