Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: Generic Function to Uncompress Files

Tags:

r

I need to read multiple compressed files with different formats of compression. I do not wish to manually uncompress all the files. I would like R to handle the uncompression and reading independent of the compression format. This is where I'm stuck.

I could construct a function with a switch case sort of structure for zip - unzip, gz - gzfile, etc. but I would like to know if there already is some function that can uncompress files irrespective of the compression format.

Any suggestions are appreciated. Thanks a lot!

PS: I know out that read.table can read (some, if not all) compressed files. However, I've been inching towards data.table::fread (because it is much faster), and that seems to not be able to read compressed files (http://r.789695.n4.nabble.com/fread-on-gzipped-files-td4663116.html - yet?). I would prefer temporarily uncompressing and using fread rather than using read.table.

like image 262
TheComeOnMan Avatar asked Sep 24 '13 12:09

TheComeOnMan


1 Answers

Then here's an upvote :-)

Btw I don't think there is a generic "uncompress" function that does the magic for you (like in any of the shell languages). The options may be simply too broad -- but I suspect you cover 80% of the cases with zip/tar/rar.

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

like image 55
rlegendi Avatar answered Nov 17 '22 13:11

rlegendi