I had blogged earlier about a proof-of-concept for how to convert an R Markdown Notebook into an IPython Notebook. The idea was to allow R users to author reproducible documents in R Markdown, but be able to seamlessly convert into HTML or an IPython Notebook, which allows greater interactivity.
This is an update to the same post that makes use of the native R kernel for the IPython Notebook, being developed by @takluyver.
As noted earlier, the bulk of the work here is done by notedown, a python module that helps create IPython notebooks from markdown. The approach I have taken here is to convert the RMarkdown file into a Markdown file using a custom knitr
script, and then using notedown to render it as an IPython notebook.
If you want to test this out, you will first need to install notedown
$ pip install notedown
The next step is to convert the Rmd
source into html
and ipynb
. For the sake of convenience, I have added a Makefile that will do it all. Just run make all
and it will create example.html using knit2html
and example.ipynb using knitr
and notedown
. So you get two birds with one stone!
Now, to open the ipython notebook, you will need to install the native R kernel. Installation instructions can be found here. Once you have installed all dependencies, you can open the notebook from the command line using:
ipython notebook --KernelManager.kernel_cmd="['R', '-e', 'IRkernel::main(\'{connection_file}\')']"
The notebook will not contain any output, since I set eval = F
while converting it. You will need to select Cell > Run All
from the toolbar to automatically execute all cells and embed output. I am presuming there might be a mechanism in the IPython Notebook architecture to trigger this execution from the command line.