[R] R script

Dirk Eddelbuettel edd at debian.org
Thu Oct 18 20:36:13 CEST 2001


On Thu, Oct 18, 2001 at 02:01:54PM -0600, Clark Christensen wrote:
> Is there some way run an R script from the command line?  Can I put a 
> line at the top of the file like I would for a bash or perl script?  For 
> example, a such a script (test.r) might look like.
> 
> #!/usr/bin/R
> 
> x <- c(1:10)
> print(x)
> 
> 
> running ./test.r at the command line doesn't work.  So is there a way to 
> do this?  Am I missing something, or do I just have to start R and 
> source() the script file (sans #!/usr/bin/R) like I'm already doing?

Try it as a shell wrapper around R:

#!/bin/sh
R --vanilla --silent <<EOF
x <- c(1:10)
print(x)
EOF

You can add --slave to the R call to suppress the command echos.

Hth, Dirk

-- 
Three out of two people have difficulties with fractions.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list