Skip to content

Commit

Permalink
fread.gzipped: update function to check compression based on file con…
Browse files Browse the repository at this point in the history
…tent and allow to decompress .bgz files
  • Loading branch information
alexg9010 committed Feb 5, 2019
1 parent 988113d commit 9dc5721
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions R/backbone.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,26 @@ fread.gzipped<-function(filepath,...){


# decompress first, fread can't read gzipped files
if (R.utils::isGzipped(filepath)){
if (R.utils::isGzipped(filepath, method = "content")){

if(.Platform$OS.type == "unix") {
filepath=paste("gunzip -c",filepath)
# being on unix we can pass comand
cmd = paste("gunzip -c",filepath)
## Read in the file
fread(cmd = cmd,...)
} else {
# on windows we have to decompress first
ext = if( endsWith(filepath,".bgz") ) "bgz" else "gz"
filepath <- R.utils::gunzip(filepath,temporary = FALSE, overwrite = TRUE,
remove = FALSE)
remove = FALSE, ext = ext, FUN = gzfile)
## Read in the file
fread(file = filepath,...)
}


}

## Read in the file
fread(filepath,...)


}
# reads a table in a fast way to a dataframe
Expand Down

0 comments on commit 9dc5721

Please sign in to comment.