Introducing roux

roux is a tool for running R scripts and creating pretty and practical output from the results. Roux is an R package which helps roux to work. For the moment, roux is a bash script which is hard-coded to use Pygments and to output HTML, but in time I’ll work to adapt this to use other highlighters and output formats, and to be platform-independent if possible.

I wrote recently about why you would want a tool for running R scripts and viewing the output in a browser and I explained a little about how it was implemented. This is basically the same tool only a little more refined, slightly easier to install and use.

The main advance is that this script now redefines the plot() function itself. This means it will create separate png images for each plot you draw, regardless of whether you make an explicit call to a graphics device. In fact if you do call quartz() or any other graphics device, it gets ignored. More testing is needed to be sure this is the sensible behaviour in every case. I don’t yet have support for the add=TRUE plot parameter for example. However this and other exceptions should be able to be dealt with.

This is nowhere near perfect, it won’t work if you trigger a graph other than via plot(), for example, but I think the core idea is extensible enough to be able to eventually accommodate at least the majority of situations. One option I may consider is to start a new image for each graphics device but just ignore it if the file size is 0, so that if a call to quartz() is followed by a call to plot(), the image triggered by quartz() just gets ignored. Suggestions and scripts which don’t work will be happily received.

The roux script is now shorter and simpler. Instead of storing functions in a .RData file, now a line is prepended to your script which loads the Roux package. This has the advantage of being more explicit, and the corresponding disadvantage of showing up in your output. Also, you can now run roux from anywhere, and it will create image and html output files from whereever you run the script. So, you no longer have to be in the directory where your R script is, although of course you can run it there if you wish to. This should make it easier to clobber temporary files. Also, once the Roux package is installed in the normal way, it will be available to your R, so there is no longer any need to have a .R helper file.

So, to run this, you now need to install:

And, because I love showing off what this can do, here’s a really nice self-contained R tutorial and here is what the output from running this R script looks like. (By the way, there are lots more R resources by Ajay Shah here.)

Update: I have written an install script. It assumes you have Python and Mercurial installed. USE AT YOUR OWN RISK.