I’ve just started using rpy2 with Python. I’ve installed it and am able to do basic things, like call R’s plot function from inside Python. For everything I’ve done, I’ve used import calls like:
import rpy2
import rpy2.robjects
From robjects I can do most things I want to do. However, if I want to use things like ggplot2, I am unable to get the relevant imports to work. Following the steps here, I try:
from rpy2.robjects.packages import importr
But I get an error message telling me that there is no module called “packages.” I’m not really sure why this is happening, as I am able to import other things from robjects, like rpy2.robjects.numpy2ri. I’m hoping this is some obvious problem other people have dealt with! I did some googling and tried messing around with the env variable $PYTHONPATH but I don’t think that is the issue.
You can use the normal
library()command from robjects.r to load a library in rpy2 2.0.x:Or you can upgrade to the 2.1 alpha and see if the new way works for you.