[R] compress data on read, decompress on write

Ramon Diaz-Uriarte rdiaz02 at gmail.com
Thu Feb 28 19:18:14 CET 2008


Dear All,

I'd like to be able to have R store (in a list component) a compressed
data set, and then write it out uncompressed. gzcon and gzfile work in
exactly the opposite direction. What would be a good way to handle
this?

Details:
----------

We have a package that uses C; part of the C output is a large sparse
matrix. This is never manipulated directly by R, but always by the C
code. However, we need to store that data somewhere (inside an R
object) for further calls to the functions in our package. We'd like
to store that matrix as part of the R object (say, as an element of a
list). Ideally, it would be stored in as compressed a way as possible.
Then, when we need to use that information, it would be decompressed
and passed to the C function.

I guess one way to do it is to have C deal with the compression and
uncompression (e.g., using zlib or the bzip2 libraries) and then use
readBin, etc, from R. But, if I can, I'd like to avoid our C code
having to call zlib, etc, so as to make our package easily portable.


Thanks,

R.

-- 
Ramon Diaz-Uriarte
Statistical Computing Team
Structural Biology and Biocomputing Programme
Spanish National Cancer Centre (CNIO)
http://ligarto.org/rdiaz



More information about the R-help mailing list