Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to directly perform write.csv in R into tar.gz format?

I have a big data.frame that I want to write into a compressed CSV file. Is there any way to directly write the data into a CSV.TAR.GZ compressed file instead of performing write.csv/gzip steps in order to reduce DISK access?

Thanks.

like image 493
imriss Avatar asked Jul 05 '13 15:07

imriss


1 Answers

Use gzfile (or bzfile for bzip2 archiving, or xzfile for xz archiving).

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

PS. If you only have one data frame, surely you don't need tar.

like image 196
Hong Ooi Avatar answered Nov 15 '22 04:11

Hong Ooi