[R] Command line and R

Angelo Secchi secchi at sssup.it
Wed Nov 9 14:48:58 CET 2005




On Wed, 09 Nov 2005 12:25:37 -0000 (GMT)
(Ted Harding) <Ted.Harding at nessie.mcc.ac.uk> wrote:

> On 09-Nov-05 Roger Bivand wrote:
> > On Wed, 9 Nov 2005, Angelo Secchi wrote:
> >> Hi,
> >> I wrote a small R script (delta.R) using commandArgs(). The script
> >> works from the shell in usual way
> >> 
> >> R --no-save arg1 < delta2.R
> >> 
> >> Suppose arg1 is the output of another shell command (e.g. gawk,
> >> sed ...). Is there a way to tell R to read arg1 from the
> >> output of the previous command? Any other workaround?
> > 
> > Use shell variables, possibly also Sys.getenv() within R as well as or 
> > instead of commandArgs().
> 
> If it's a fairly simple shell comand (and even if it isn't, though
> it could get tricky for complicated ones) you can use the "backquote"
> trick (called, in well-spoken circles, "command substitution"):
> 
>   R --no-save `shellcmd` < delta2.R
> 
> As in all shell command lines, wherever you have a command (including
> arguments etc.) between backquotes, as exemplified by "`shellcmd`" above,
> the output of the command (as sent to stdout) replaces "`shellcmd`" in
> the command-line. This could be a lot of stuff (depending on what
> "shellcmd" is), or just one value, or whatever.
> 
> Best wishes,
> Ted.

Thanks.
A.



> 
> 
> --------------------------------------------------------------------
> E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
> Fax-to-email: +44 (0)870 094 0861
> Date: 09-Nov-05                                       Time: 12:25:32
> ------------------------------ XFMail ------------------------------


-- 
========================================================
 Angelo Secchi                     PGP Key ID:EA280337
========================================================
  Current Position:
  Research Fellow Scuola Superiore S.Anna
  Piazza Martiri della Liberta' 33, Pisa, 56127 Italy
  ph.: +39 050 883365
  email: secchi at sssup.it	www.sssup.it/~secchi/




More information about the R-help mailing list