1

I have been trying to unzip multiple large files. I have been trying to use this function provided by Adam Bethke (see here) and below:

decompress_file <- function(directory, file, .file_cache = FALSE) {

    if (.file_cache == TRUE) {
       print("decompression skipped")
    } else {

      # Set working directory for decompression
      # simplifies unzip directory location behavior
      wd <- getwd()
      setwd(directory)

      # Run decompression
      decompression <-
        system2("unzip",
                args = c("-o", # include override flag
                         file),
                stdout = TRUE)

      # uncomment to delete archive once decompressed
      # file.remove(file) 

      # Reset working directory
      setwd(wd); rm(wd)

      # Test for success criteria
      # change the search depending on 
      # your implementation
      if (grepl("Warning message", tail(decompression, 1))) {
        print(decompression)
      }
    }
}

However, I keep getting the error message:

Error in system2("unzip", args = c("-o", file), stdout = TRUE) :
'"unzip"' not found

Any help/guidance would be much appreciated.

Anna Rouw
  • 69
  • 2
  • 8

1 Answers1

0

system2 is accessing your system terminal. The linked by you answer points out that it is designed for UNIX computers (like Mac and Linux). It is NOT designed for Windows machines, but you can easily install Ubuntu on Windows nowadays (on a separate partition). Please make sure the unzip is installed on your machine too; In your terminal, simply run unzip.

polkas
  • 3,797
  • 1
  • 12
  • 25