R directly save data as zip file

It's possible using gzip.

write.csv(mtcars, file=gzfile("mtcars.csv.gz"))

This can be accomplished pretty easily using the readr functions and gzip.

library(readr)

write_tsv(mtcars, file.path(dir, "mtcars.tsv.gz"))

write_csv(mtcars, file.path(dir, "mtcars.csv.gz"))

From the docs, ?write_csv:

The write_*() functions will automatically compress outputs if an appropriate extension is given. Three extensions are currently supported: .gz for gzip compression, .bz2 for bzip2 compression and .xz for lzma compression. See the examples for more information.

Tags:

Compression

R

Zip