IPython notebook and rmagic/rpy2: cannot find module ri2py (OSX 10.8.5, python 2.7, R 3.1)
ipython, macos, r, rpy2
Solution
Are you using `%load_ext rmagic`?
If so, try using `%load_ext rpy2.ipython` instead.
This is one of the new features in version 2.4.0.
Problem
I'm trying to use the rmagic extension for the IPython notebook, using Python 2.7.6 via Enthought Canopy. When I try the following example: ``` import numpy as np import pylab X = np.array([0,1,2,3,4]) Y = np.array([3,5,4,6,7]) pylab.scatter(X, Y) %Rpush X Y %R lm(Y~X)$coef ``` I get an error: ``` AttributeError Traceback (most recent call last) <ipython-input-7-96dff2c70ba0> in <module>() 1 get_ipython().magic(u'Rpush X Y') ----> 2 get_ipython().magic(u'R lm(Y~X)$coef') … /Users/hrob/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/IPython/extensions/rmagic.pyc in eval(self, line) 212 res = ro.r("withVisible({%s})" % line) 213 value = res[0] #value (R object) --> 214 visible = ro.conversion.ri2py(res[1])[0] #visible (boolean) 215 except (ri.RRuntimeError, ValueError) as exception: 216 warning_or_other_msg = self.flush() # otherwise next return seems to have copy of error AttributeError: 'module' object has no attribute 'ri2py' ``` I can't find anyone else who's had the same problem and don't know enough to solve it myself. There is no definition for ri2py in conversion.py though. I initially had installed Anaconda and was running python notebook through that, with exactly the same results. rpy2 (version 2.4.0) installed successfully but when I test it I get 1 expected failure as follows: ``` python -m 'rpy2.robjects.tests.__init__' … testNewWithTranslation (testFunction.SignatureTranslatedFunctionTestCase) ... expected failure ``` I don't know if that's related. Can anyone suggest what the problem might be and how I might fix it? Are the versions of python, R, etc. that I'm using compatible or do I need to re-install/update something?