title: R pdf() usage inside a function()
body: <p>I have some code in R that generates a multipage pdf file:</p>
  
  <pre><code>pdf("myplot.pdf", width=8.5, height=5)
  
  My.Plot(my.data, var1, var2)
  My.Plot(my.data, var3, var2)
  My.Plot(my.data, var4, var2)
  
  dev.off()
  </code></pre>
  
  <p><em>My.Plot() is just a function that parses the necessary data and then uses ggplot to create a graph</em></p>
  
  <p>The above works just fine. However, when I put this code in a function, there are no plots generated and the output PDF can not be read/opened.</p>
  
  <pre><code>generate.PDF &lt;- function(my.data) {    
      pdf("myplot.pdf", width=8.5, height=5)
  
      My.Plot(my.data, var1, var2)
      My.Plot(my.data, var3, var2)
      My.Plot(my.data, var4, var2)
  
      dev.off()
  }
  </code></pre>