The need of this came from the fact that read.csv
can read zip files directly but data.table::fread
cannot take connections as input since it requires random file seek. There is simple usage of data.table::fread(paste0("zcat < ", PATH_TO_FILE))
but that depend on command line tool gzip, which is not always available in windows. See here for more details.
The code is based on R.utils::decompressFile
with lots of modifications:
- no more removing input file. I lost several data files and puzzled too much time because of this even if I read the document and knew this behavior in the beginning.
- According to
?connections
, `gzfile`` can handle gz, bzip2, xz. No need to specify and use different functions for uncompress. - The only exception is
gzfile
cannot handle zip. We can useunzip
to decompress file directly without need of connections.unzip
does not support Unicode filenames as introduced in zip 3.0. See more in?unzip
for its li