Monday, February 27, 2017

Calling R from inside a Jupyter notebook

I use mostly python + jupyter in my research--in this case astronomical data science--workflow. One challenge I have been facing recently is dealing with time series. Some of the routines I need to use were written in R. There are versions of them for python but they seem to be inferior. The question then is: is it possible to easily interface with R functions from inside a jupyter python notebook? The answer is--amazingly--yes!

To illustrate how easy this is, I create a jupyter notebook available on Gist. This notebook demonstrates how to:

  1. generate some simple mock data with python/numpy
  2. import that data on R
  3. perform a linear fit using R's methods and load the results back to python
  4. plot the R fit with python
This may sound complicated but it really isn't.