People rave about Sweave and the literate programing paradigm and I am guilty as charged. I speak Sweave, I think Sweave, I dream Sweave. As a matter of fact my default mode of operation is Sweave and anything else is an exception. I do all my math and stats in Sweave, I write manuscripts in Sweave, my lab notebook is in Sweave, I manage my personal finances with Sweave, and I do my presentations indulging in a most satisfying threesome with LaTeX, R and Beamer.
Being this enamoured with Sweave might suggest that, in my eyes at least, Sweave might be perfect. But like all intimate relationships there are rough patches and when you say tomato and it says tomahto it takes work to iron out the differences. So let’s take a close and brutally honest look at the apple of my eye. Not that I am questioning my relationship, on the contrary, identifying and acknowledging the limitations of Sweave will hopefully help me become more in tune with it and perhaps even find new ways of working with it. An alternative interpretation would be that it is far easier to be the devil’s advocate and enumerate Sweave’s cons rather than its innumerable pros.
So here it is, my Top 10 things that suck about Sweave and to keep everyone on the edge of their seats I will not be proposing any solutions (of course I have solutions, but giving those away here would take the fun out of it).
- If you collaborate, you will likely be to only one speaking Sweave so good luck with that. If you are thick-headed you’ll send your .Rnw file to your non-Sweave literate collaborators only to get it back as a .Rnw.docx file full of Track Changes and Word formatting. Been there done that.
- Your Sweave code will likely break in future versions of R and as packages change and/or become obsolete. Sigh, been there done that.
- If your R code is computationally time-consuming weaving will be excruciatingly slow (but it will give an opportunity to update your Facebook status without feeling guilty about it).
- Coding in Sweave is slower than doing straight R. Ain’t no such thing as fast prototyping when speaking Sweave. This reminds me of Treebeard in LOTR: “You must understand, young Hobbit R apprentice, it takes a long time to say anything in Old Entish Sweave. And we never say anything unless it is worth taking a long time to say“. By the time you have set up your LaTeX preamble for your Hello World program your Sweave illiterate office mate would have submitted his/her program to CRAN as a fully fledged (but poorly documented) R package.
- Syntax highlighting of Sweave files, i.e. getting both the LaTeX and R code right, is horrendous at best but mostly absent (the scroll bar idiosyncrasies of Emacs ESS invalidates any merits this beast may have).
- Code chunks can only span full functions. As a result, for long functions that really should be broken up into several code chunks, one has the create sub-functions of within-function processes thus taking the path through the valley of the shadow of spaghetti code.
- When errors occur during the LaTeXification the line number of the error refers to the .tex file, not the .Rnw file.
- Debugging the R and LaTeX code within the Sweave file is a hairy beast. To address LaTeX issues one has to weave the .Rnw file, debug the LaTeX in the resulting .tex file and implement the fixes in the original .Rnw file. To debug the R code one has to tangle the .Rnw file, debug the R code in the resulting .R file and implement the fixes in the original .Rnw file. I you are still with me after that brain-full…, respect!
- It’s annoying having to rerun all the R code every time one adds a new chunk of code. Seriously, it’s plain stupid.
- It is clunky impossible to integrate codes across several source documents. For example, if one would like to reuse code chunks between Sweave files…, well, good luck with that.
And finally, a personal message to Friedrich: my sincere apologies if I came across to harshly. Rest assure that my devotion and admiration for Sweave is unwavering.
This is from the “Mario’s Entangled Bank” blog (http://pineda-krch.com) of Mario Pineda-Krch, a theoretical biologist at the University of Alberta.
Filed under: humour, R, Sweave