[R] Using Rscript to read from a file

Saptarshi Guha saptarshi.guha at gmail.com
Thu Oct 14 17:49:08 CEST 2010


Hello,
I have this script which will be invoked as

Rscript a.r < a.r

a.r follows

#!/usr/bin/Rscript --vanilla
f=file("stdin")
while(TRUE){
    y=readLines(f,n=1,warn=TRUE)
  if(length(y)==0) break else print(y)
}


But it only reads one line from a.r
How can I read line by line from standard input?

Thank you
Saptarshi



More information about the R-help mailing list