Issue when creating zip file from directory

Viewed 1967

I have trouble with creating zip file from R. The same code worked perfectly at work with R version 3.4.2, 32 bit computer.

Now I am trying to run the same thing on R version 3.5.1, 64 bit computer, and the zip() command does not seem to work. What is going on?

zip(zipfile = "test.zip",files=list.files(getwd())) 
#create zip from whole directory, on 1st machine it works, now nothing happens

I checked the source code for zip() and when I debug it, I found out that system2 command does nothing.

  zip <- function (zipfile, files, flags = "-r9X", extras = "", zip = Sys.getenv("R_ZIPCMD", 
                                                                                  "zip")) 
  {
    if (missing(flags) && (!is.character(files) || !length(files))) 
      stop("'files' must a character vector specifying one or more filepaths")
    args <- c(flags, shQuote(path.expand(zipfile)), shQuote(files), 
              extras)
    if (.Platform$OS.type == "windows") 
      invisible(system2(zip, args))
    else invisible(system2(zip, args))
  }

# I run this manually when trying to debug, nothing happens;
system2(zip, args) ## zip is a parameter here, not a function
####
Browse[2]> zip
[1] "zip"
Browse[2]> args
[1] "-r9X"                    "\"bla.zip\""            
[3] "\"[Content_Types].xml\"" "\"_rels\""              
[5] "\"docProps\""            "\"xl\""                 
[7] "" 

For example absurd call does not give an error.

system2("blablađ",2) ## does nothing but no error or warning either

I am stuck trying to understand how does system2() function works and what do I need to change to create a compressed folder.

Thanks

EDIT: After taking the account the help from comment, I got following error:

Browse[2]> system2(zip, args,stderr = T)
Error in system2(zip, args, stderr = T) : '"zip"' not found

SOLVED: After installing Rtools for version 3.5 it worked.

1 Answers

From the zip help:

zip(zipfile, files, flags = "-r9X", extras = "", zip = Sys.getenv("R_ZIPCMD", "zip"))

zip A character string specifying the external command to be used.

As you can see, the zip function has an argument zip to specify the external command to be used. On my machine it is:

λ where zip
C:\Oracle\Ora11\BIN\zip.exe
C:\Program Files\Rtools\bin\zip.exe

The zip program is available in Rtools, but it is also available on any (Windows?) machine, usually.

To check whether zip is found by R, type:

> Sys.which("zip")
                              zip 
"C:\\Oracle\\Ora11\\bin\\zip.exe" 

If you get "", that means zip is not in the path, and if it is neither in the environment variable R_ZIPCMD, you have to specify its path in the zip argument.

Related