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
Le 18.02.2005 22:52, Christian Schulz a ?crit :> 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. >The following works for me: echo "x<-1:10 ;y<-21:30 ;lm(y ~ x)" | R --vanilla Romain> 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 >-- Romain FRANCOIS : francoisromain at free.fr page web : http://addictedtor.free.fr/ (en construction) 06 18 39 14 69 / 01 46 80 65 60 _______________________________________________________ Etudiant en 3eme ann?e Institut de Statistique de l'Universit? de Paris (ISUP) Fili?re Industrie et Services http://www.isup.cicrp.jussieu.fr/
Christian Schulz <ozric at web.de> writes:> 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.It would probably help to use proper R syntax:> (x<-1:10 ;y<-20:30 ;lm(y ~ x))Error: syntax error What were those outer parentheses supposed to be good for?> 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)Yes. But it is not an R issue, so look up the details in the bash manual. -- 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
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."
On 18-Feb-05 Christian Schulz wrote:> 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.Two things wrong with the above: 1. Use y<-21:30 with x<-1:10 otherwise "variable lengths differ"! 2. While (x<-1:10) returns the value of the assignment, i.e. [1] 1 2 3 4 5 6 7 8 9 10 (which I suppose you wanted to see, as a check), even (x<-1:10 ;y<-20:30) is a syntax error in R, and (x<-1:10 ;y<-20:30 ;lm(y ~ x)) is an even bigger one! You can emulate completely the typing in of commands by using the "-e" option to echo, which allows you to use escape sequences in the string, so that you can insert "\n" where you would usually press Return. So: echo -e "(x<-1:10) \n (y<-21:30) \n lm(y~x)" | R --vanilla will work fine; and here the "(...)" cause R to print out confirmation of the assignments "x<-1:10" and "y<-1:10" which normally you perhaps wouldn't want, so the "production" version of the above would be echo -e "x<-1:10 \n y<-21:30 \n lm(y~x)" | R --vanilla> 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)Of course it is, as in export LIM="10" echo -e "x<-1:$LIM \n y<-21:30 \n lm(y~x)" | R --vanilla but just make sure that you escape "$" when you need it as part of an R syntax, e.g. when accessing named components of a list. Thus: echo -e "x<-1:$LIM \n y<-21:30 \n lm(y~x)\$fitted.values" | R --vanilla Compare with what happens when you don't escape the "$", i.e. echo -e "x<-1:$LIM \n y<-21:30 \n lm(y~x)$fitted.values" | R --vanilla You need to take similar precautions for all shell metacharacters which might occur in an R statement (see "man bash" for these). Hoping this helps, Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk> Fax-to-email: +44 (0)870 094 0861 Date: 19-Feb-05 Time: 08:53:58 ------------------------------ XFMail ------------------------------