Re: [R] commandArgs usage and --args invokation

From: Dirk Eddelbuettel <>
Date: Sun 01 Apr 2007 - 15:13:46 GMT


For R 'shell scripts', esp. on Unixy system (incl OS X), our littler frontend can be of help. See


as well as the SVN archive

    svn checkout littler

Using littler scripts, you can then do things like

    edd@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")


    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@basebud:~> pace.r 3 25

    Miles   :  3
    Time    :  25
    Pace    :  8 min 20 sec


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

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Mon Apr 02 01:22:22 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 01 Apr 2007 - 21:31:00 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.