[R] reading a text file, one line at a time

Dimitri Liakhovitski dimitri.liakhovitski at gmail.com
Sun Aug 15 18:47:26 CEST 2010


In read.table - under parameters can't you specify the number of lines
to be read in?
You could create a loop and read them one by one.
Dimitri

On Sun, Aug 15, 2010 at 10:58 AM, Data Analytics Corp.
<walt at dataanalyticscorp.com> wrote:
> Hi,
>
> I have an upcoming project that will involve a large text file.  I want to
>
>  1. read the file into R one line at a time
>  2. do some string manipulations on the line
>  3. write the line to another text file.
>
> I can handle the last two parts.  Scan and read.table seem to read the whole
> file in at once.  Since this is a very large file (several hundred thousand
> lines), this is not practical.  Hence the idea of reading one line at at
> time.  The question is, can R read one line at a time?  If so, how?  Any
> suggestions are appreciated.
>
> Thanks,
>
> Walt
>
> ________________________
>
> Walter R. Paczkowski, Ph.D.
> Data Analytics Corp.
> 44 Hamilton Lane
> Plainsboro, NJ 08536
> ________________________
> (V) 609-936-8999
> (F) 609-936-3733
> walt at dataanalyticscorp.com
> www.dataanalyticscorp.com
>
> _____________________________________________________
>
>
> --
> ________________________
>
> Walter R. Paczkowski, Ph.D.
> Data Analytics Corp.
> 44 Hamilton Lane
> Plainsboro, NJ 08536
> ________________________
> (V) 609-936-8999
> (F) 609-936-3733
> walt at dataanalyticscorp.com
> www.dataanalyticscorp.com
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Dimitri Liakhovitski
Ninah Consulting
www.ninah.com



More information about the R-help mailing list