title: Is there a command to export the current plot?
body: <p>I'm creating a whole mess of charts, and would like to export the produced charts as PDF. It's possible to click 'export' in the Plot tab in rstudio and manually select "save plot as PDF", of course, and I'd prefer not to wrap every single one of my sections in <code>pdf()</code> / <code>dev.off()</code>.</p>
  
  <p>Ideally I'd like a function that would take the currently-displayed plot in RStudio and save it with the parameters I'd like (format /filename / width / height).</p>
  
  <p>Thoughts?</p>
  
  <p><strong>Update</strong></p>
  
  <p>As per @naught101's suggestion - for a 5x7 (inch!) pdf file which is a convenient size to be pasted into an A4 Word document, the following works well:</p>
  
  <pre><code>dev.copy2pdf(file="example.pdf", width = 7, height = 5)
  </code></pre>
  
  <p>Better yet, as an easily-called function with default dimensions:</p>
  
  <pre><code>dopdf &lt;- function(filename = "dopdf.pdf", pdf.width = 7, pdf.height = 5) {
   dev.copy2pdf(file=filename, width = pdf.width, height = pdf.height)
  }
  </code></pre>
  
  <p>While using <code>ggplot2</code> would have let me save using the <code>ggsave</code> function, <code>dev.copy2pdf</code> is a good generic solution (answering my original question).</p>