title: Download and Read Zip CSV file in R
body: <p>I am trying to download and read a zipped csv file from Kaggle within an R script. After researching other posts including <a href="https://stackoverflow.com/questions/23899525/using-r-to-download-zipped-data-file-extract-and-import-csv">post1</a> and <a href="https://stackoverflow.com/questions/3053833/using-r-to-download-zipped-data-file-extract-and-import-data">post2</a> I have tried:</p>
  
  <pre><code># Read data with temp file
  url &lt;- "https://www.kaggle.com/c/rossmann-store-sales/download/store.csv.zip"
  tmp &lt;- tempfile()
  download.file(url, tmp, mode = "wb")
  con &lt;- unz(tmp, "store.csv.zip")
  store &lt;- read.table(con, sep = ",", header = TRUE)
  unlink(tmp)
  </code></pre>
  
  <p>the read.table command throws an error: </p>
  
  <pre><code>Error in open.connection(file, "rt") : cannot open the connection
  </code></pre>
  
  <p>I have also tried:</p>
  
  <pre><code># Download file, unzip, and read
  url &lt;- "https://www.kaggle.com/c/rossmann-store-sales/download/store.csv.zip"
  download.file(url, destfile = "./SourceData/store.csv.zip", mode = "wb")
  unzip("./SourceData/store.csv.zip")
  </code></pre>
  
  <p>Unzip throws the error: </p>
  
  <pre><code>error 1 in extracting from zip file
  </code></pre>
  
  <p>Bypassing the unzip command and reading directly from the zip file</p>
  
  <pre><code>store &lt;- read_csv("SourceData/store.csv.zip")
  </code></pre>
  
  <p>Throws the error: </p>
  
  <pre><code>zip file ... SourceData/store.csv.zip cannot be opened
  </code></pre>
  
  <p>I prefer to use the temp file, but at this point I'll use either approach if I can make it work.</p>