Skip to content
Prev 83066 / 398502 Next

Linux command

In LINUX and other unixes you can also put your R commands in a so-called "here 
file", which resides within the script file that calls R; so you don't need two 
separate files.  Taking Marc Schwartz' example, you could have make the 
following script file (call it say "tsst"):

#!/bin/sh
R --slave --vanilla <<XXXX
  # Example from ?lm
  ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
  trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
  group <- gl(2,10,20, labels=c("Ctl","Trt"))
  weight <- c(ctl, trt)
  anova(lm.D9 <- lm(weight ~ group))
XXXX

Then do:
chmod +x tsst
./tsst

The here file is the part between <<XXXX and XXXX.  Also, arguments to the 
script are interpretable within the here file.  So for example:

#!/bin/sh
R --slave --vanilla <<YYY
  tt <- scan("$1")
  print(mean(tt))
YYY

would read data from a file given as an argument in calling the script.


Cheers, Pierre

Marc Schwartz offered the following remark on 12/19/05 14:43...