write.csv can handle the following:
library(data.table)
DT = data.table(a = 1:10, b = 11:20)
tmp.gz = tempfile(fileext = '.csv.gz')
gzf = gzfile(tmp.gz, 'w')
write.csv(DT, gzf)
close(gzf)
But fwrite cannot:
tmp.gz = tempfile(fileext = '.csv.gz')
gzf = gzfile(tmp.gz, 'w')
fwrite(DT, gzf)
close(gzf)
Error: is.character(file) && length(file) == 1 && !is.na(file) is not TRUE
(because the gzf object is more complicated than just being a file path).
fwrite(DT, tmp.gz), as expected, does not perform compression -- the output is the same size as fwrite(DT, tempfile()) (which is different from write.csv).
I'm using fwrite to pipe some output to Vowpal Wabbit, trying to use the --compressed argument to save on some disk space. Workaround is to fwrite then gzip, but this seems sub-optimal.
write.csvcan handle the following:But
fwritecannot:(because the
gzfobject is more complicated than just being a file path).fwrite(DT, tmp.gz), as expected, does not perform compression -- the output is the same size asfwrite(DT, tempfile())(which is different fromwrite.csv).I'm using
fwriteto pipe some output to Vowpal Wabbit, trying to use the--compressedargument to save on some disk space. Workaround is tofwritethengzip, but this seems sub-optimal.