Search code examples
pythonlinuxrubunturpy2

How to have recognized all the libraries Rpy2 R


How to have recognized all the libraries Rpy2 R.

Rpy2 not recognizing the libraries, utils, and tools.

import rpy2.robjects as robjects

R = robjects.r  

>>> R['library']("utils")

RVector - Python:0x7f65fc85cfc8 / R:0x19bb980

>>> R['library']("tools")

RVector - Python:0x7f65fc85f5a8 / R:0x2419140

(>>> from rpy2.robjects.packages import importr Traceback (most recent call last): File "", line 1, in ImportError: No module named packages )

as I can update Rpy2 to load all the libraries without problems or R that can be done.

PS: I use R 2.10 and python 2.6 on ubuntu


Solution

  • In order to get the importr command to work, you probably need to upgrade your version of rpy2 -- try checking your version:

    print rpy2.__version__
    

    I believe you need version 2.1.0 or greater. The following works for me under 2.1.7 but not on 2.0.3:

    In [1]: import rpy2.robjects as robjects
    
    In [2]: R = robjects.r  
    
    In [3]: from rpy2.robjects.packages import importr
    
    In [4]: importr("utils")
    Out[4]: <rpy2.robjects.packages.SignatureTranslatedPackage object at 0x1e96310>
    

    I'm not sure what you're trying to do, as those libraries should work without any extra importing, as Gavin has mentioned.