« American Community Survey analyzed with R | Main | In-depth analysis of Twitter activity and sentiment, with R »

January 26, 2016


Feed You can follow this conversation by subscribing to the comment feed for this post.

For my purposes, showing and running the code has always been only half the battle, with the other half being in generating documents and automated reports to share the results with others, especially non-programmers. R + RStudio Server + knitr + Markdown/LaTeX has been my go-to for this. Can the R/Python + Jupyter system rival this?

Hi Steve. I have done lots of reporting with knitr in RStudio and I know what you mean regarding the reporting battle. To me your question revolves around sharing results with a mostly non-technical audience. For that purpose I would stick with knitr+RStudio for two main reasons: 1) one can suppress the code output which might confuse non-tech folks and 2) I believe it simply looks more professional at this point.

For my purposes, here, I am wishing to combine python and R into a pipeline, sharing variables from one code cell to the next. In knitr+RStudio, when using only R, variables persist from code chunk to code chunk. However, if you have a code chunk using the python engine in your Rmd document, variables do not persist to the next code chunk (even if your whole knitr markdown is using the python engine). Knitr+RStudio markdown files are not what we like to call 'polyglot' (yet).

That being said, one can automate the creation of a report using a notebook file and the jupyter nbconvert command-line tool. See here.

Hope that helps.

Neat! I completely agree with your point - we should use the tools that are best fit to the job, instead of taking unfounded/irrational decisions.

The first example notebook don't seem to work out of the box; I had to insert two lines before creating the dataframe object:

from rpy2.robjects import pandas2ri

After this things worked like a charm; second example notebook worked fine first time.

I'm using R 3.2.3 on Ubuntu 14.04, jupyter 4.0.6, python 3.4.3

Hello Edward. Please ensure you ran the code cell:

%load_ext rpy2.ipython

You should not need to use pandas2ri if using the latest rpy2.

Which versions of rpy2 and pandas do you have? These are my specs:

R 3.2.3
Python 3.4.3
OS: Mac OS X 10.10.5

Micheleen, awesome post. Beaker sounds like an awesome way to combine R, python and Julia. My only issue with notebooks is that they are not nearly as user friendly as editing an R markdown file in an editor. Or is there a way to edit a notebook file as something other than a json file? thanks

Thank you for your post. I really liked it.
I however, tried to install rpy2 in windows 7 and even ubuntu (trusty) with no luck. Is there a special trick for making it work? like which version of python did you use. was it 32 bit or 64 bits. I think if you put a video in youtube it would have a lot of views since it seems to be very hard to install rpy2.

Hi, Just want to say that I did spent a lot of time (8+hrs) trying to make rpy2 work with no luck, in both windows and ubuntu. Maybe I should just give up on the task.

Hello Ricardo. Thank you for your feedback! To edit as markdown, I'd convert my notebook file (in the json .ipynb format) to markdown, latex or maybe just script with, for example:

jupyter nbconvert --to markdown mynotebook.ipynb

Hello Luis. Thanks for the feedback! Yes, rpy2 can be tricky to install (esp. on Windows). My suggestion would be to stick with ubuntu for now. You could look into using wheels (pre-built) modules for rpy2 (which is how I got things working on Windows). I have 64 bit python (v3.4.3). I will take the suggestion of an instructional video on this seriously.

Hi Micheleen,

Nice blog entry.

Yes, unfortunately there is no official support for Windows at the moment. However, contributed binaries for Windows can be found here: http://www.lfd.uci.edu/~gohlke/pythonlibs/

Regarding the issue on Windows you are experiencing, there is a patch in the repository and it will be included in the next bugfix release (rpy2-2.7.8).

Otherwise, main page for the project is now http://rpy2.bitbucket.org



Hi Micheleen,, I managed to make it work at the end. I had problems with the R_HOME and R_USER paths. ALso I had to modify the Rprofile.site so the starting working directory of Rstudio and its libraries wouldnt be changing paths when working on Rstudio.
Thanks again,

Hi Micheleen, where did you get the syntax `%%R -i x,y -o mycoef` as I've looked extensively in the ryp2 document page but could not find this elegant way of calling R.

Can you provide further info? Thanks!


The comments to this entry are closed.

Search Revolutions Blog

Got comments or suggestions for the blog editor?
Email David Smith.
Follow revodavid on Twitter Follow David on Twitter: @revodavid
Get this blog via email with Blogtrottr