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 that. What you *can* do is stuff like [pd at blueberry pd]$ cat > xxx.RR #!/bin/sh R --vanilla --quiet << __END__ x <- c(1:10) print(x) __END__ [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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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? Clark -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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? > > Clark > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > 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 > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._I have had the same problem by trying to install R.1.3.1. I m not specialist so my answer will be perhaps not clear or stupid. I think that you must copy the R script in the directory as /usr/local/bin/R and it must be "world readable" (chmod u, g and o +r) and executable(+x). If it's impossible for you to copy the script you have not probably the authorization (so see you "root"). The other solution is to type all directory path which contains /.R (I think that is /usr/bin/.R for you) the thing before ./R must be all the path where is the script (/usr/bin). Bye good luck. Aboubakar Maitournam. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._