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

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Thu, 31 May 2007 09:16:15 -0400

Try this:

con <- pipe("findstr /b 5 myfile.dat")
open(con, "r")
DF <- read.fwf(con, widths = c(1, 1, 2)) # replace with right args close(con)

On 5/31/07, Tobin, Jared <TobinJR_at_dfo-mpo.gc.ca> wrote:
> The responses are much appreciated, thanks.
>
> findstr works and saves a lot of time. I didn't however have much
> success with that exact code persay; I get an error message that I don't
> understand, as follows:
>
> > c1 <- read.fwf(pipe("findstr /b 5 my.file"), ...)
> Error in readLines(con, n, ok, warn, encoding) :
> 'con' is not a connection
> Error in close(file) : no applicable method for "close"
>
> I did however have success with pipe using readLines, albeit in a very
> clumsy fashion:
>
> > c1 <- readLines(pipe("findstr /b 5 my.file"))
> > write(c1, file="temp.dat")
> > t1 <- read.fwf("temp.dat", ...)
>
> Do you receive the same error message as above when using pipe with
> read.fwf?
>
> --
>
> jared tobin, student research assistant
> dept. of fisheries and oceans
> tobinjr_at_dfo-mpo.gc.ca
>
> -----Original Message-----
> From: Gabor Grothendieck [mailto:ggrothendieck_at_gmail.com]
> Sent: Tuesday, May 29, 2007 10:51 PM
> To: Charles C. Berry
> Cc: Tobin, Jared; r-help_at_stat.math.ethz.ch
> Subject: Re: [R] Partially reading a file (particularly)
>
> On 5/29/07, Charles C. Berry <cberry_at_tajo.ucsd.edu> wrote:
>
> 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 Thu 31 May 2007 - 13:30:58 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 - 20:33:27 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.