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


______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to