[R] R script

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Thu Oct 18 20:21:30 CEST 2001

Clark Christensen <christensen_c at yahoo.com> writes:

> 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?

It might become possible in the future. There are a couple of
complications that get in the way: You cannot use a shell script
(which /usr/bin/R is) in a #! line, and even if you could, R would be
called with the script as an argument, and it currently doesn't handle

What you *can* do is stuff like

[pd at blueberry pd]$ cat > xxx.RR
R --vanilla --quiet << __END__
 x <- c(1:10)
[pd at blueberry pd]$ chmod +x xxx.RR
[pd at blueberry pd]$ ./xxx.RR
>  x <- c(1:10)
>  print(x)
 [1]  1  2  3  4  5  6  7  8  9 10

   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
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