[R] storage and single-precision

Mike Miller mbmiller+l at gmail.com
Thu Sep 8 17:56:31 CEST 2011


On Thu, 8 Sep 2011, William Dunlap wrote:

> Use gzcon() to make a compressed connection and any function that write 
> to a connection will write compressed data.  E.g.,
>
>  > con <- gzcon(file("tempfile.junk", "wb"))
>  > x <- as.integer(rep(c(-127, 1, 127), c(3,2,1)))
>  > writeBin(x, con, size=1)
>  > close(con)
>  > q("no")
>  bill:158% zcat tempfile.junk | od --format d1
>  0000000 -127 -127 -127    1    1  127
>  0000006
>
> (In this tiny example the gzip'ed file is bigger than the equivalent 
> one, but it is gzip'ed.)


That's a great function.  Thanks for the tip.  Apparently it works in both 
directions.  That is, I would also use gzcon for readBin:

Description:

      ‘gzcon’ provides a modified connection that wraps an existing
      connection, and decompresses reads or compresses writes through
      that connection.  Standard ‘gzip’ headers are assumed.

Perfect.  Thanks again.

Mike


More information about the R-help mailing list