Thursday, January 31, 2013

Sweave, R and Latex

If you use R for your statistical analysis and graph plotting needs and then use those figures in your Latex documents, you will find this interesting. Sweave is a package in R which lets takes in an .rnw file (which contains usual text from a tex document with R commands embedded in it), compiles it (in R) and gives out a tex file. This tex file can in turn be compiled by pdflatex (if you have figures) or plain latex to get a properly formatted pdf/ps/dvi file with relevant R output. There are many excellent examples on the interwebs and I strongly recommend using Sweave right away.  The beauty of this approach is that on can save a lot of time by not spending on choosing the appropriate dimensions of a a png or an eps output. Sweave does it for you.

Edit: If you want to insert a R-generated figure then add this to your tex file:

\begin{figure}
\begin{center}
<
\end{center}
\end{figure}


If you want to insert text from R but properly tabbed and with all the ampersands added, then add these lines to your tex file:

<

No comments:

Post a Comment