I have a very large zip file and i am trying to read it into R without unzipping it like so:
temp <- tempfile("Sales", fileext=c("zip")) data <- read.table(unz(temp, "Sales.dat"), nrows=10, header=T, quote="\"", sep=",") Error in open.connection(file, "rt") : cannot open the connection In addition: Warning message: In open.connection(file, "rt") : cannot open zip file 'C:\Users\xxx\AppData\Local\Temp\RtmpyAM9jH\Sales13041760345azip'
To read a zip file and extract data from it to R environment, we can use the download. file() to download the zip, then unzip() allows to unzip the same and extract files using read.
Install the Chrome extension from the Chrome Web Store. Or open your Google Drive account > New > More > Connect more apps. Search for ZIP Extractor and install it. The ZIP Extractor screen gives you the option to select the files to extract.
R user John Christie points out a handy feature introduced in R 2.10: you can now read directly from a text file compressed using gzip or other file-compression tools.
How to zip files in R. To zip files in R, use the zip() function. The zipped file is stored inside the current directory unless a different path is specified in the zip() function argument. The zip() method creates a new ZIP archive, and it overwrites the output file if it exists.
If your zip file is called Sales.zip
and contains only a file called Sales.dat
, I think you can simply do the following (assuming the file is in your working directory):
data <- read.table(unz("Sales.zip", "Sales.dat"), nrows=10, header=T, quote="\"", sep=",")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With