17

I found zip and the RCompression package but can they do:

write.zip(x, file = "foo.zip")

as you'd with write.csv?

I'm also aware of gzfile.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Rico
  • 1,998
  • 3
  • 24
  • 46

2 Answers2

24

It's possible using gzip.

write.csv(mtcars, file=gzfile("mtcars.csv.gz"))
Ven Yao
  • 3,680
  • 2
  • 27
  • 42
4

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.

Rich Pauloo
  • 7,734
  • 4
  • 37
  • 69
JNorm
  • 41
  • 1