Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Sweave is an awesome utility for including the output of R code in a LaTeX document which I have started using regularly.

TeXShop is my favorite editor/viewer for LaTeX under Mac OS X for many reasons. One of which is the speed of the edit -> compile -> view process which it enables. Therefore, I have been reluctant to use Sweave in the past because of the extra LaTeX compilation step that is not supported by default in TeXShop.

Recently, my friend Charlie Sharpsteen first showed me this way to get around this with a custom “engine”. The engine file looke like this:

Sweave.engine

 #!/bin/bash export PATH=$PATH:/usr/texbin:/usr/local/bin R CMD Sweave “$1” pdflatex “\${1%.*}“ 

Place this file in ~/Library/TeXShop/Engines/, make sure PATH includes the location of you TeX distribution.

Make sure executable permissions (like 744) are set on both files or TeXShop will give an error message. Now open (or re-open) TeXShop and select “Sweave” from the list at the top left. Now you can use command-t to compile Sweave and view your document in one step! Thanks Chuck!