Skip to content

shelling out to R for one command

4 messages · David Firth, Paul Meagher, Dirk Eddelbuettel

#
I am developing a PHP script and want to use R to get the probability of a
t-value.

This just requires that I issue one R statement and output the result.

The problem I am having is that R will accept batch input but I am not
sure that it will accept a "one-liner" (i.e., "/usr/local/bin/R qt(.975,
20)"  does not work but you get the idea).

Is there a way to pass R a one-liner without having to put it into a batch
file and submit it to R as a batch job.

Regards,
Paul Meagher




-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Saturday, Nov 16, 2002, Paul Meagher wrote:

            
various possibilities for this using unix redirection
e.g.

david% echo "3+4" | R --slave
[1] 7

One could for example set this up as a shell script "Roneliner",
so that

david% Roneliner "3+4"
[1] 7

Possibly it's more economical also to use arguments
     --no-restore --no-save --no-readline --gui=none
in addition to --slave.

David
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
David Firth wrote
This works nicely:

echo "q(.975, 20)" | R --slave
Or this:

paul% R1 "3+4"
[1] 7

BTW, what do you think Roneliner would look like as a shell script?
The most economical startup options would be good to know.

My guess would be just  --vanilla option?

Regards,
Paul

  
    
#
On Sat, Nov 16, 2002 at 11:34:50PM -0400, Paul Meagher wrote:
"There's more than one way to do it". Here's just one:

edd at sonny:~> cat /tmp/R1
#!/bin/sh -e
echo "$@" | R --slave

edd at sonny:~> /tmp/R1 "print(3+4); qnorm(0.5)"
[1] 7
[1] 0

Dirk