Building a reporting system with R, Brew and Latex

If you search for methods for generating PDF reports in R you will mostly find articles about Sweave. Sweave does the job: it lets you insert R code into a latex template and then compile it to generate a PDF report. I’d been using it for some time and was pretty happy with it.

However, as I found myself adding more tricky stuff (complex tables, internal links, etc) into the latex templates, I realized it would be very useful to be able to include loops in the template. I you think of other templating systems (Java JSPs, Ruby ERBs, etc) that’s something you tend to do quite often. But, unfortunately, Sweave does not allow loops.

That’s why I looked for alternatives. Luckily, I found Brew, a simple but very powerful templates engine created by Jeff Horner that is closer to the templates engines most web developers are used to, and does allow for loops. Brew is a generic templates engine, meaning that you can use it to create a latex, txt or html files. Actually, people tend to use it to render html files (the combination of rApache+Brew really shines). However, some people were beginning to use it to generate latex reports and as an alternative to Sweave.

Neither framework is better than the other, they are just different. Brew lets you reach a lower level at the template level and have a cleaner separation between logic (the R script that usually precomputes the results) and view (the template where you decide how to show these results). However, that also makes it more verbose than Sweave.

Recently, I was kindly invited to give a talk about all this at the III Jornadas de Usuarios de R that took place in Madrid last November. I leave the presentation here.

Advertisements


Deixa un comentari

Fill in your details below or click an icon to log in:

WordPress.com Logo

Esteu comentant fent servir el compte WordPress.com. Log Out / Canvia )

Twitter picture

Esteu comentant fent servir el compte Twitter. Log Out / Canvia )

Facebook photo

Esteu comentant fent servir el compte Facebook. Log Out / Canvia )

Google+ photo

Esteu comentant fent servir el compte Google+. Log Out / Canvia )

Connecting to %s