Console output using rpy2 does not work in Jupyter Notebook

Using Jupyter Notebook, when I execute a function from an R package (in my case Climatol) from a notebook that uses the R kernel, messages are displayed as output that report the procedures that are being done. Nothing new.

enter image description here

The code block used is this:


# Apply function (from R kernel)
homogen('Vel',2011,2012,tinc='6 hour',expl=TRUE)

Now, using the Python kernel from another notebook, when I call the same function through rpy2 applying the same parameters, I don’t get the same messages that appear in the previous image. Instead I get this: enter image description here

This time, the code block used is this:

from rpy2.robjects import r
from rpy2.robjects.packages import importr


# Apply function ( from Python kernel)
r["homogen"]("Vel",2011,2012,tinc="6 hour",expl=r['as.logical']("T"))

I ran the mentioned Python code from Sublime Text and in this case the messages are displayed: enter image description here

The messages are also displayed when running the code from the Windows console, which leads me to think that the downside is Jupyter. That being said, how can I get those messages using Jupyter?

I’m using Python 3.7 and the version of rpy2 is 2.9.4

Thanks for the help.


rpy2 it not fully supported on Windows. Callbacks used to set how R output is handled are likely not working, which results in the issue you are observing.

If this improves in will be in more recent rpy2 versions. The latest rpy2 release is 3.3.6 for example.

Otherwise, for better compatibility on Windows consider running rpy2/jupyter in Docker, or if it works in a WSL (Windows Subsystem for Linux).

Leave a Reply

Your email address will not be published. Required fields are marked *