R exdir does not exist error

A couple of years late but I still get this error when trying to use unzip(). It appears to be a bug because the man pages for unzip state if exdir is specified it will be created:

exdir The directory to extract files to (the equivalent of unzip -d). It will be created if necessary.

A workaround I've been using is to manually create the necessary directory:

dir.create("directory")
unzip("file-to-unzip.zip", exdir = "directory/")

A pain, but it seems to work, at least for me.


On a windows setup: I had this error when I had exdir specified as a path. For me the solution was removing the trailing / or \\ in the path name.

Here's an example and it did create the new folder if it didn't already exist

locFile <- pathOfMyZipFile
outPath <- "Y:/Folders/MyFolder"
# OR
outPath <- "Y:\\Folders\\MyFolder"

unzip(locFile, exdir=outPath)

This can manifest another way, and the documentation doesn't make clear the cause. Your exdir cannot end in a "/", it must be just the name of the target folder.

For example, this was failing with 'exdir' does not exist:

unzip(temp, overwrite = F, exdir = "data_raw/system-data/")

And this worked fine:

unzip(temp, overwrite = F, exdir = "data_raw/system-data")

Presumably when unzip sees the "/" at the end of the exdir path it keeps looking; whereas omitting the "/" tells unzip "you've found it, unzip here".

Tags:

R

Unzip

Rstudio