ipython/ipython — pull request #2711 by rmcgibbo (2012-12-20 23:50:09+00:00)
Title: rmagic extension: saving ggplot graphs

This is a response to [an email](http://comments.gmane.org/gmane.comp.python.ipython.devel/9765) on IPython-dev, which mentioned that its hard to get plots generated by ggplot in R using the rmagic extension to render in the notebook.

The reason for the issue is that, using the standard R graphics, the rmagic extension manually saves the graph in a tempdir with a special file name and then loads them up to send to the display publisher. Since it doesn't cd into that directory, there's no way to just save your ggplot graph in the right spot.

While ggplot is an R extension, it is very widely used. Wikipedia calls it one of the more popular R packages. https://en.wikipedia.org/wiki/Ggplot2

This PR runs its code in a little R try/catch block, so if you don't have ggplot loaded up (or installed), it's no problem.

demo: http://nbviewer.ipython.org/4349612/