views:

141

answers:

2

hi all, i'd like to create a zip archive from within R, and need maximal cross-platform compatibility, so I would prefer not to use a system("zip") command.

Within utils there's zip.file.extract (aka unzip), which uses [a lot of] c code, derived from zlib 1.1.3 within a file called dounzip.c I couldn't find any similar capabilities for creating zip files.

it's also tricky to construct a specific google query for "cran create zip" or equivalent!

Also, a tar will not suffice, I need to creating zip's to use as input for another set of non-R tools.

i'd appreciate any pointers?

cheers, mark

+1  A: 

As usual the amazing Omega Project for Statistical Computing is a valuable resource! Take a look at the Rcompression package and try, for example, something like:

?gzip    
txt <- paste(rep("This is a string", 40), collapse = "\n")
v <- gzip(txt))
writeBin(v, "test.txt.zip")

HTH

Paolo
hi Paulo,thanks, that's getting closer to what i need.What I didn't say clearly enough is that I have a directory full of various files which already exist... I then need to turn them, possibly recursively into a zip archive... from what I can tell: "This [Rcompression] package is a basic interface to the zlib and bzip2 facilities for compressing and uncompressing data that are in memory rather than in files"
mjc
+1  A: 

I think the command gzfile() may also do what you're looking for. Also note that in the upcoming version 2.10.0 there are some enhancements to compression functions that may be relevant. (see https://svn.r-project.org/R/trunk/NEWS -- the svn server may ask you to accept a certificate)

Peter
thanks Peter,there's a new tar() and untar() command coming in 2.10, but no zip() !!mark
mjc