Home > Back-end >  How to open a gzip file in R?
How to open a gzip file in R?

Time:04-10

unzip("fasta.gz")

Warning message: In unzip("fasta.gz") : error 1 in extracting from zip file

I am trying to unzip a zip file but it is not working what am I doing wrong?

CodePudding user response:

Would something like this work?

# Input:
#   file_name: the name of the file to unzip
#
# Output:
#   file_name: the name of the unzipped file
#
# Usage:
#   file_name <- unzip_file(file_name)
#
unzip_file <- function(file_name) {
  file_name <- gzfile(file_name)
  file_name <- unzip(file_name)
  file_name <- gzfile(file_name)
  file_name
}

CodePudding user response:

No, you are trying to decompress a gzip file, not a zip file. Those are two different things. unzip is for zip files. Use gunzip() or gzfile() for gzip files.

  • Related