January 3, 2016

I write most of my papers in LaTeX. This time, I’m writing an IB Biology IA and need to include R-generated graphs and figures. Usually I just generate the PDFs seperately and include them inside of the document using `\includegraphics`, but I wanted to give Sweave a try.

I created a Makefile and setup my documents just so then gave it a spin. Aaaand error!

``````! LaTeX Error: File `Sweave.sty' not found.
``````

Sigh… LaTeX errors.

After a bit of internet investigation, here’s how I fixed the problem. (This is for my own personal reference, but I hope it helps you as well.)

First we need to find the path where R was installed. If you didn’t install it via homebrew, then just find `R.framework` in your filesystem.

``````\$ brew info R
Software environment for statistical computing
http://www.r-project.org/
# a lot of output, but here is what we're looking for
/usr/local/Cellar/r/3.2.2 (2175 files, 59M) *
# ...

\$ sudo ln -s /usr/local/Cellar/r/3.2.2/R.framework/Resources/share/texmf/ /usr/local/texlive/2015/texmf-dist/tex/latex/Sweave
\$ sudo texhash
# Success!
``````

The symlink paths might be different depending on your version and installation of LaTeX, but the general idea is to make LaTeX aware of R’s `sty` files.

Hope this helps!

Next post: Make Awesome (Easy) Aeropress Coffee