R: general function for unpacking files

I need to read several compressed files with various compression formats. I do not want to manually extract all the files. I would like R to handle compression and reading regardless of the compression format. This is where I am stuck.

I could build a function with a sorting structure for zip-unzip, gz-gzfile, etc., but I would like to know if there is any function that can decompress files regardless of the compression format.

Any suggestions are welcome. Many thanks!

PS: I know that read.table can read (some, if not all) compressed files. However, I was advancing to data.table::fread (because it is much faster), and it seems like it cannot read compressed files ( http://r.789695.n4.nabble.com/fread-on- gzipped-files-td4663116.html - for now?). I would prefer temporarily unchecking and using fread rather than using read.table.

+7
r
source share
1 answer

Then here's the top :-)

Btw I don’t think there is a common function "uncompress" that does the magic for you (for example, in any of the shell languages). The options may just be too wide, but I suspect that you cover 80% of cases with zip / tar / rar.

Just write a simple uncompress <- function(type = c("zip", "tgz", "tar", "arj :-)))")) {...} , which was your original intention.

+1
source share

All Articles