[R] R cmd batch with parameters

AniaK anna.kedzierska at crg.es
Mon Dec 6 22:36:32 CET 2010


hello!
I'm trying to make a very simple calculation using R that would called
from bash with two parameters, the names of the input and output files.
the first one is just an 4 by 100 numerical table- the function finds
the index of the maximal elements in each columns and writes it into the
output file.
I cannot deal somehow with passing the parameters to the function it
works from R with the parameters set fixed.

I'd really very much appreciate comment where I go wrong and possible
solutions. I paste the code below:

spinR <- function(){
   args<-(commandArgs())
   dataVec <- read.table(args[1], sep=" ")
   attach(dataVec)
   a<-dim(dataVec)
   indMax<- 1:a[2]
   for(i in 1:a[2]){
      indMax[i]<-which.max(dataVec[,i])
    }
   write.table(indMax, file=args[2], col.names=FALSE, row.names=FALSE)
}
How would I pass the arguments via command line? Are the file names
passed in quotes?

thank you so much in advance!!!
Ania

-- 
View this message in context: http://r.789695.n4.nabble.com/R-cmd-batch-with-parameters-tp3075376p3075376.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list