r function unzip error 1 in extracting from zip file

社会主义新天地 提交于 2019-12-08 15:15:21

问题


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.


回答1:


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")



回答2:


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.




回答3:


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.




回答4:


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.




回答5:


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




回答6:


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.



来源:https://stackoverflow.com/questions/37221184/r-function-unzip-error-1-in-extracting-from-zip-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!