RE: [R] skip lines on a connection

About this list Date view Thread view Subject view Author view Attachment view

From: Vadim Ogranovich (vograno@evafunds.com)
Date: Sun 02 May 2004 - 15:28:46 EST


Message-id: <C698D707214E6F4AB39AB7096C3DE5A54B32D9@phost015.intermedia.net>

Andy,

It is surprising that scan() attempts to read anything at all: note that
I set nmax=0, which AFAIK means read no lines.

Thank you for a reference to replicate(). I didn't know about it.

Thanks,
Vadim

-----Original Message-----
From: Liaw, Andy [mailto:andy_liaw@merck.com]
Sent: Saturday, May 01, 2004 5:28 PM
To: Vadim Ogranovich; r-help@stat.math.ethz.ch
Subject: RE: [R] skip lines on a connection

Your scan() call doesn't work because default argument what=0; i.e., it
expects numeric data. You probably can just use what="".

The other alternative is to just loop readLines() n times, reading one
line at a time. It probably won't be too bad in terms of time, and
surely will save on memory usage.

(Try using replicate().)

HTH,
Andy

> From: Vadim Ogranovich
>
> Unfortunately, seek only works in terms of bytes not lines and I only
> know how many lines I need to skip, but not bytes.
>
>
> -----Original Message-----
> From: Gabor Grothendieck [mailto:ggrothendieck@myway.com]
> Sent: Saturday, May 01, 2004 3:44 PM
> To: r-help@stat.math.ethz.ch
> Subject: Re: [R] skip lines on a connection
>
>
>
>
> ?seek
>
> Vadim Ogranovich <vograno <at> evafunds.com> writes:
>
> :
> : Hi,
> :
> : I am looking for an efficient way of skipping big chunks of
> lines on a
> : connection (not necessarily at the beginning of the file).
> One way is
> to
> : use read lines, e.g. readLines(1e6), but a) this incurs the overhead
> of
> : construction of the return char vector and b) has a (fairly remote)
> : potential to blow up the memory.
> :
> : Another way would be to use scan(), e.g.
> :
> : scan(con, skip=1e6, nmax=0)
> :
> : but somehow this doesn't work:
> :
> : > scan(con, skip=10, nmax=0)
> : Error in scan(con, skip = 10, nmax = 0) :
> : "scan" expected a real, got "A;12;0;"
> :
> : I can stick to readLines, but am curious if there is a better way.
> :
> : I use R-1.8.1 on RH-7.3.
> :
> : Thanks,
> : Vadim
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>

------------------------------------------------------------------------
------
Notice: This e-mail message, together with any attachments,...{{dropped}}

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Mon 31 May 2004 - 23:05:07 EST