I am having trouble finding clear documentation on how to set up a batch file for a Sweave document on Windows XP.
I am using the batch files that are found here
I have created a batch file names run.bat which contains the following:
Sweave myFile.Rnw
The first thing I do in my Sweave file after setting the wd is read in a dataset using the RODBC package:
library(RODBC)
fetch <- odbcConnect("myDatabase")
myData <- "select * from myTable"
x <- sqlQuery(fetch, myData)
odbcCloseAll()
When I run my batch file, I receive the following error:
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'
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?
Related question here
I found an immediate solution to my problem, though understand there are certain limitations to this method. I abandoned using the CRAN provided .bat files for dynamically finding the appropriate path to R and hardcoded the path to R as such:
This
.batfile will fire up R, run the scriptrun.rwhich contains two commands:and then cleans up the intermediate
.logand.auxfiles from the LaTeX output. Obviously, the bulk of the work is done inmyFile.Rnwbut this will atleast let me click one button, perform my analysis, and generate the PDF file.If someone can think of a way to make this more efficient, I’d appreciate it.