title: Windows batch R Sweave error loading packages
body: <p>I am having trouble finding clear documentation on how to set up a batch file for a Sweave document on Windows XP.</p>
  
  <p>I am using the batch  files that are found <a href="http://cran.r-project.org/contrib/extra/batchfiles/" rel="nofollow noreferrer">here</a></p>
  
  <p>I have created a batch file names <code>run.bat</code> which contains the following:</p>
  
  <pre><code>Sweave myFile.Rnw
  </code></pre>
  
  <p>The first thing I do in my Sweave file after setting the wd is read in a dataset using the <code>RODBC</code> package:</p>
  
  <pre><code>library(RODBC)
  fetch &lt;- odbcConnect("myDatabase")
  myData &lt;- "select * from myTable"
  x &lt;- sqlQuery(fetch, myData)
  odbcCloseAll()
  </code></pre>
  
  <p>When I run my batch file, I receive the following error:</p>
  
  <pre><code>Error: chunk 2
  Error in library(RODBC) : there is no package called RODBC
  In addition: Warning message:
  In library(package, lib.loc = lib.loc, character.only = TRUE, logical.return = TRUE, :
      there is no package called 'xtable'
  </code></pre>
  
  <p>Obviously these packages do exist and are functional, but something isn't right in the permissions or it isn't finding the right directories. Any thoughts?</p>
  
  <p>Related question <a href="https://stackoverflow.com/questions/1188544/getting-windows-to-start-r-in-batch-mode-using-the-start-command">here</a></p>