[R] scan

ben@zoo.ufl.edu ben at zoo.ufl.edu
Thu Mar 15 00:16:30 CET 2001


  Another solution (which Brian Ripley has probably already given, I seem
to get stuff from R-help very slowly):

 if you look at the help for ?file and ?scan, you'll see

Alternatively, `file' can be a `connection', which will be
opened if necessary, and if so closed at the end of the
function call.

 So if `file' is an open connection, it *won't* be closed and re-set at
the end of the read.  So:

cat("1 2 3","4 5 6","7 8 9",file="tmp.dat",sep="\n")
myfile <- file("tmp.dat",open="r")  ## open for reading
p <- scan(myfile,nlines=1)
q <- scan(myfile,nlines=1)

 Ed Borasky is probably right that in the long run using a database or
Perl would be more efficient, but this might get you through ...

On Wed, 14 Mar 2001, M. Edward (Ed) Borasky wrote:

> On Wed, 14 Mar 2001, Heberto Ghezzo wrote:
>
> > Hello, I have a problem. I have to read a HUGE file which has to be
> > line processed, so I would like to use scan like
> > p <- scan(pfile,what=c(0,0,0,"",0,""),nlines=1)
> > but it continues to read the first line, so I have to add a skip and
> > increment the skip after each read.
> > It takes forever to read a test file of 1 Mb, the real one is in 60's Mb
> > Is there a way to read line by line an ASCII file without having to
> > reread the part already read?
> > Thanks for any help.
>
> There are two fairly easy ways to do this sort of thing, depending on the type
> of expertise available:
>
> 1. Load the huge file into a database with a good text file import capability,
> like Microsoft Access, then use RODBC to read the data you're interested in
> with a query. This is what I do for manual analysis; I have lots of huge files.
>
> 2. Write a Perl script to extract the relevant data to a smaller file and then
> read the smaller file directly in R. This is what I do for my *automated*
> analysis.
>
> BTW, I've processed files of 120-odd MB this way on 400 MHz Pentium-class
> machines with 128 MB of RAM.
> --
> znmeb at aracnet.com (M. Edward Borasky) http://www.aracnet.com/~znmeb
>
> What is it about
>
>  @replace(@string(@log(10000)*@atan(1),9),0,0, at char(112)&@char(105)&@char(61))
>
> that you don't understand?
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>

-- 
318 Carr Hall                                bolker at zoo.ufl.edu
Zoology Department, University of Florida    http://www.zoo.ufl.edu/bolker
Box 118525                                   (ph)  352-392-5697
Gainesville, FL 32611-8525                   (fax) 352-392-3704

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list