[R] R & bash script

Pierre Kleiber pkleiber at honlab.nmfs.hawaii.edu
Sat Feb 19 00:23:25 CET 2005


One way to run multiple R commands within a bash script is with a "here 
document".  See http://www.tldp.org/LDP/abs/html/here-docs.html

Here is an excerpt of a bash script showing its use -- notice that several 
bash variables are referenced within it:

#!/bin/bash
              .
              .
R --slave --vanilla --quiet --no-save  <<EEE
#  ---edit so path to R-graphics/.RData is correct---
attach("/home/mfcl/R-graphics/.RData")
if( $keep ) {
   junk <- paste("$1",".medley.png",sep="")
   print(paste("saving plotfile",junk))
} else {
   junk <-  "$tempfile"
}
png(file=junk,height=$ht,width=$wd)  # open plot file
plotmedley("$1")                # do the plot
dum <- dev.off()                # close file
system(paste("display",junk))   # display it
EEE
              .
              .
 

Cheers, Pierre

Christian Schulz wrote:
> Hi
> 
> how is it possible to use more than one command when i'm
> didn't want use R CMD BATCH for specific reason?
> 
> $ echo "(x<-1:10)" | R --vanilla
> works
> 
> $ echo "(x<-1:10 ;y<-20:30 ;lm(y ~ x))" | R --vanilla
> works not.
> 
> Is it further possible using  bash variables like $i  from a loop
> in the bash echo call  i.e.   dm$x$i$k <- 
> read.data("dmdata$x$i$k.dat",header=T)
> 
> many thanks for a starting point!
> christian
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 

-- 
-----------------------------------------------------------------
Pierre Kleiber, Ph.D       Email: pkleiber at honlab.nmfs.hawaii.edu
Fishery Biologist           Tel: 808 983-5399 / 808 737-7544 (hm)
NOAA FISHERIES - Honolulu Laboratory         Fax: 808 983-2902
2570 Dole St., Honolulu, HI 96822-2396
-----------------------------------------------------------------
  "God could have told Moses about galaxies and mitochondria and
   all.  But behold... It was good enough for government work."




More information about the R-help mailing list