4

The readr package in the tidyverse has the option to automatically unpack a zip file and convert it to a tibble. But I have a zip file that holds multiple csv files. In the line of code below, SSPdataZip has three files in it. When I run it I get a warning "Multiple files in zip ..." and the name of the one it chooses. I know the name of the one I want but can't figure out how to tell read_csv what it is. Is there an option I'm missing?

temp <- readr::read_csv(SSPdataZip, col_names = TRUE, guess_max = 2000)
JerryN
  • 2,356
  • 1
  • 15
  • 49

1 Answers1

4

I believe you can use unz to achieve this:

readr::read_csv(unz(description = "SSPdataZip", filename = "FileName.csv"), col_names = TRUE, guess_max = 2000)

Amar
  • 1,340
  • 1
  • 8
  • 20
  • 1
    One edit I would make for clarity sake is to say "... filename = "FileName.csv"). Sometimes a function has the filename first, but unz has the description, in this case the zip file name, first. – JerryN Apr 13 '18 at 02:42
  • Good point. Corrected for the sake of being explicit. I assume everyone will investigate `unz` themselves by looking at the docs, figuring out the syntax. – Amar Apr 13 '18 at 03:54