What is the best way in R
to determine if a file is or isn't compressed? Is there any particular function to check that?
I am asking about something different than looking at filename extension e.g.
grepl("^.*(.gz|.bz2|.tar|.zip|.tgz|.gzip|.7z)[[:space:]]*$", filename)
In R, do this:
filetype = summary( file('yourfile.gz') )$class
If it's gzipped, filetype
will be gzfile
Note: you may also want to assign file to a variable and close the connection after
filetype <- function(path){
f = file(path)
ext = summary(f)$class
close.connection(f)
ext
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With