title: Automate zip file reading in R
body: <p>I need to automate R to read a csv datafile that's into a zip file.</p>
  
  <p>For example, I would type:</p>
  
  <pre><code>read.zip(file = "myfile.zip")
  </code></pre>
  
  <p>And internally, what would be done is:</p>
  
  <ul>
  <li>Unzip <code>myfile.zip</code> to a temporary folder</li>
  <li>Read the only file contained on it using <code>read.csv</code></li>
  </ul>
  
  <p>If there is more than one file into the zip file, an error is thrown.</p>
  
  <p>My problem is to get the name of the file contained into the zip file, in orded to provide it do the <code>read.csv</code> command. Does anyone know how to do it?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Here's the function I wrote based on  @Paul answer:</p>
  
  <pre><code>read.zip &lt;- function(zipfile, row.names=NULL, dec=".") {
      # Create a name for the dir where we'll unzip
      zipdir &lt;- tempfile()
      # Create the dir using that name
      dir.create(zipdir)
      # Unzip the file into the dir
      unzip(zipfile, exdir=zipdir)
      # Get the files into the dir
      files &lt;- list.files(zipdir)
      # Throw an error if there's more than one
      if(length(files)&gt;1) stop("More than one data file inside zip")
      # Get the full name of the file
      file &lt;- paste(zipdir, files[1], sep="/")
      # Read the file
      read.csv(file, row.names, dec)
  }
  </code></pre>
  
  <p>Since I'll be working with more files inside the <code>tempdir()</code>, I created a new dir inside it, so I don't get confused with the files. I hope it may be useful!</p>