[R] Command Line Expressions
Barry Rowlingson
B.Rowlingson at lancaster.ac.uk
Fri Mar 5 13:18:11 CET 2004
Pingping Zheng wrote:
> Is it possible to run R in command line to evalute R expressions
> and return results to stdout, something like
>
> Or do a simple calculation
> >R CMD -e "sin(1.2)"
> >0.932039
Yes, with a bit of trickery!
R on Unix will read from standard in, so you need to feed your R from
stdin - typically use 'echo' to send a string to stdin.
You'll also want to use --slave to stop all of R's startup messages,
and probably --no-save as well.
Also, you may need to cat() the expression:
$ echo "cat(sin(1.2))" | R --no-save --slave
0.932039
...otherwise you get R's default print labelling:
$echo "sin(1.2)" | R --no-save --slave
[1] 0.932039
Baz
More information about the R-help
mailing list