Re: [R] Partially reading a file (particularly)

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Tue, 29 May 2007 21:21:25 -0400

On 5/29/07, Charles C. Berry <cberry_at_tajo.ucsd.edu> wrote:
> On Tue, 29 May 2007, Tobin, Jared wrote:
>
> > Hello,
> >
> > I am trying to figure out if there exists some R command that allows one
> > to be
> > particularly selective when reading a file. I'm dealing with large
> > fixed-width data
> > sets that look like
> >
> > 539001..
> > 639001..
> > 639001..
> > ...
> > 539002..
> > 639002..
> > ...
> >
> > Presently, I am using read.fwf to read an entire file, but I am
> > interested only in
> > reading those records beginning with 5. I have been unable to find help
> > in any of
> > the suggested resources.
>
> Assuming you have 'grep' in your path,
>
> res <- read.fwf( pipe( "grep '^5' my.file" ) , <other args> )
>
> will do it.
>
> grep will usually be found on linux/unix systems and Mac OS X. The
> 'Rtools' toolkit for windows has grep, I believe.

On windows XP we can also use findstr which comes with Windows:

         res <- read.fwf( pipe( "findstr /b 5 my.file" ) , <other args> )



R-help_at_stat.math.ethz.ch 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. Received on Wed 30 May 2007 - 01:28:53 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 31 May 2007 - 13:31:37 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.