r function unzip error 1 in extracting from zip file

Richmodo picture Richmodo · May 14, 2016 · Viewed 30.5k times · Source

Environment: Windows 7 OS RStudio Version 0.99.491

I have been programming in R for about 4 months via the Coursera Data Science curriculum, but I have NEVER been successful in using the unzip function.

I've looked at the forums for hours for potential solutions, syntax problems, undefined arguments, etc., but to no avail. I eventually unzip the contents manually and proceed with the assignment, but I am tired of not knowing why it is not working.

Here are a few examples of the error:

fileName <- "StormData.zip"

unzip(fileName, exdir = mainDir,subDir)

Warning message: In unzip(fileName, exdir = mainDir, subDir) : error 1 in extracting from zip file

unzip(fileName)

Warning message: In unzip(fileName) : error 1 in extracting from zip file

unzip(fileName, "stormdata.csv")

Warning message: In unzip(fileName, "stormdata.csv") : error 1 in extracting from zip file

unzip(fileName, "stormdata.csv", list = TRUE)

Error in unzip(fileName, "stormdata.csv", list = TRUE) : zip file 'StormData.zip' cannot be opened

Any suggestions would be greatly appreciated.

Answer

Piyush Verma picture Piyush Verma · May 17, 2016

I too was getting that error 1 message when trying to unzipping a zip file. Glitch in my case was the conflict between working directory and zip file path.

My case was:

  • My working directory was like "C:/Users/SCOTT/Desktop/Training"
  • While my zip file was located in "C:/Users/SCOTT/Desktop/Training/house_consumption_data"

When I was trying to execute this:

     unzip("house_data.zip")

Possibly your file is in a different folder.