0

I know that this question has been asked exhaustively on this site, but I cannot find any question which addresses my problem.

I am trying to import multiple .csv files into R which are located in nested .zip files on my PC. The other questions seem to relate to importing a single file from a URL, which is not my issue.

I have set my working directory to the folder which contains the first .zip file, but there is another one inside of it, which then contains normal folders, and finally hundreds of .csv files which I am looking to access.

Up to now I have always manually extracted the data since I have no idea where to begin with unzipping code, but considering this folder contains around 20GB of data, I'm going to need to try something else.

Any help would be appreciated!

EDIT - CODE:

setwd("C:/docs/data/241115")
temp <- tempfile()
unzip("C:/docs/data/241115/Requested.zip",exdir=temp)
l = list.files(temp)
unzip("C:/docs/data/241115/Requested/Data Requested.zip",exdir=temp)

>  error 1 in extracting from zip file
sym246
  • 1,836
  • 3
  • 24
  • 50
  • I've found a useful answer here [read a csv file in a zipped folder with R without unzipping](https://stackoverflow.com/questions/46682818/read-a-csv-file-in-a-zipped-folder-with-r-without-unzipping) – Tiziano Aug 01 '19 at 21:40

1 Answers1

0

Without a minimal reproducible example it's difficult to know exactly where the problem lies. My best guess is that using a tempfile() is causing problems.

I would create a folder within your working directory to unzip the files to. You can do this from within R if you like:

# Create the folder 'temp' in your wd
dir.create("temp")

Now assuming your zip file is in the working directory I would unzip the first .zip in to temp in one step:

unzip("Requested.zip", exdir = "temp")

Finally, unzip the final .zip:

unzip("temp/Data Requested.zip", exdir = "temp")
Community
  • 1
  • 1
Phil
  • 4,344
  • 2
  • 23
  • 33