Knitr is a great package for integrating R code into LaTeX documents to make reproducible writeups of scientific work. In writing my proposal and dissertation I realized that it would be easier to have each chapter be a separate tex document, so that I could keep R code chunks separate, and not have to run multiple huge model fittings if I changed one of them (knitr is pretty smart with caching, although sometimes this breaks down and I have to clear the whole cache and recompile everything). To do this I have on master tex file that has each section or chapter included with the command \subincludefrom{foo/}{bar} where foo is the subdirectory of the part and bar is the name of the tex file to include.

I then create knitr bar.Rnw files which I knit separately. This produces the bar.tex file which is referenced in the master document. I then use latex to compile only the master document. The following set of bash (with auctex variables) commands is a template that, in aquamacs, will knit the current document, and then compile the master document.

Rscript -e "library(knitr); knit('%s.Rnw')"; cd ~/dissertation/; texi2pdf -c dissertation.tex

the latex command subincludefrom is from the import package which allows for the sub documents to have their own relative includes (necessary for figures) additionally, it acts like the LaTeX include command in that has some speed benefits with large documents.