Reputation: 251
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.
Upvotes: 25
Views: 75362
Reputation: 115
For me the error is fixed after I add \ backslash character to the filepath. Example: from
unzip("abc\aaa.zip")
to
unzip("abc\\aaa.zip")
Upvotes: 0
Reputation: 142
It's crucial to give the full name (including the path) of the zip-file to the unzip
function.
So instead of file.zip, it should be C:\user\name\file.zip.
In case you're using the list.files
function, one should set the full.names
option to TRUE.
Upvotes: 0
Reputation: 237
This error was happening bit differently in my case . As there was no zip file ,the issue was file was open in excel so this error was poping up .
Upvotes: 0
Reputation: 1
I had list of files to be unzipped and processed; I was facing same error "error 1 in extracting from zip file"
used full directory and set working directory code worked
files <- list.files(path="C:\\Users\\Tejas naik\\Documents\\land", pattern=".zip$")
out_dir<- "C:\\Users\\Tejas naik\\Documents\\input"
setwd("C:\\Users\\Tejas naik\\Documents\\land")
for (i in files) {
#nzip(paste(out_dir,i), exdir=out_dir)
unzip(i,exdir=out_dir)
}
Upvotes: 0
Reputation: 1
I encountered the same error using install_course_zip' with a zip file. I followed all the instructions for the command faithfully but kept getting errors relating to the 'exdir'. I moved the zip file to various directories without success.
I finally used getwd()
to get the working directory and then placed the zip file in that directory. I then was able to use the zip file name without having to use any folder structure and this worked. I still have no idea why R would not accept a different directory.
Upvotes: 0
Reputation: 102
I faced the same issue. Make sure that, you specify the correct name of the file(get it from the properties of .zip file) in the following code.
file = read.table(unzip("file_name.csv.zip"), sep = ",", header = TRUE)
In my case, Was just mentioning file_name.zip and R was throwing the error.
Also, there are two functions for unzipping files in R
1) unz - to extract single element from zip file/s 2) unzip - to extract all the present elements from the .zip file
I usually prefer unzip. If you will use unz in the above code, R will throw error again.
Upvotes: 0
Reputation: 343
This error seems to appear whenever openXLS is unable to open the specified file. It could be a wrong name, wrong directory or the file might be encrypted or password protected
Upvotes: 1
Reputation: 1
change your zip file format this error will appear while the zip format problems occur, look at your zip file it should be "rar" change it to "zip". the function works only for "zip" format files.
Upvotes: 0
Reputation: 31
I have had the same problem trying to download and unzip the same file, for the same course. And I have had problems with unzip in the past and was determined to solve it this time too.
Eventually the extension of the file turned out to be csv.bz2. And than this Extract bz2 file in R post solved my problem. After downloading the file I was able to read it directly with
stormdata <- read.csv("stormdata.zip")
without using unzip.
Upvotes: 3
Reputation: 721
I was getting the same error.
I changed the path --
from :
uzp <- "C:\\Users\\Sharvari\\Downloads\\rprog%2Fdata%2Fspecdata"
to
uzp <- "C:\\Users\\Sharvari\\Downloads\\rprog%2Fdata%2Fspecdata.zip"
and it works fine!
setwd("C:\\Users\\Sharvari\\Downloads")
uzp <- "C:\\Users\\Sharvari\\Downloads\\rprog%2Fdata%2Fspecdata.zip"
unzip(uzp, exdir = "C:\\Users\\Sharvari\\Desktop\\specdata")
Upvotes: 9
Reputation: 1379
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:
When I was trying to execute this:
unzip("house_data.zip")
Possibly your file is in a different folder.
Upvotes: 6