Forum: RForum R CMD BATCH passing parameters

Posted by Anna Kedzierska (ania)
on 2010-12-06 21:47
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
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.