Skip to content
Prev 244093 / 398506 Next

R cmd batch with parameters

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