[Tex/LaTex] Workflow in Sweave: Handling TeX errors

sweave

I've been using LaTeX and R for a few years now, but am only now bringing them together via Sweave. As I put the document together, I run my R code in its own session to verify that it works properly, then add it to the Sweave file. Then, I Sweave the file in R. This goes fine, since all the R code has checked out. When I compile the TeX file, though, there are almost invariably errors that I have made.

Finding an error in the TeX file, tracing it to the Sweave file, and re-Sweaving and TeXing isn't that difficult. It does become a pain when there are multiple errors, meaning multiple reruns of Sweave and pdftex. It would be simpler if I could fix all the errors in the TeX file, which can be rerun alone simply, and have them transfer into the Sweave file, rendering it ready for a final Sweave and TeX compile.

Any tips on how you handle this workflow?

One tip is to not make any errors, but, as an economist, I believe that the optimal number of errors is probably greater than 0.

Thanks!
Charlie

Best Answer

I also use sweave (a few months) and latex (20 years). With a reasonably fast machine, the optimal scheme is simply to rebuild often. I use "make" (on a unix-like machine) so that only the chapters whose Rnw file has changed get rebuilt into tex files. That saves a lot of sweave time.

Alternatively, you can edit the .tex file and work away at errors, and put your results back into the .Rnw file when you're ready. But that's error-prone.

If you run sweave-latex often, and fix errors as soon as you see them, then you won't make so many errors.

The other advice is to use a decent editor (e.g. emacs) that does a lot of the work for you, e.g. finishing off parenthetic blocks, begin/end environments and so forth. That prevents 2/3 of the errors you're likely to make.