title: How to get list of packages used in a knitr .Rnw document?
body: <p>Using RStudio --> CompilePDF</p>
  
  <p>In a .Rnw document to be processed with pdflatex, I'd like to get a list of all
  user (me) packages loaded via library() or require() in the document.  I tried
  to use sessionInfo(), as in</p>
  
  <pre><code>   \AtEndDocument{
     \medskip
     \textbf{Packages used}: \Sexpr{names(sessionInfo()$loadedOnly)}.
     }
  </code></pre>
  
  <p>however, what this prints is just the list of packages used by knitr itself,</p>
  
  <blockquote>
    <p>Packages used: digest, evaluate, formatR, highr, stringr, tools.</p>
  </blockquote>
  
  <p>not those I explicitly referred to.  I believe this is because knitr runs the
  code chunks within an internal environment, but I don't know how to access that.</p>
  
  <p>I know about the file cache/__packages that is created with cache=TRUE; is there
  any way to generate this automatically without caching?</p>