RPy

A simple and efficient access to R from Python

Sections
rpy rpy2
Exits
Acknowledgement 
This site is hosted by
SourceForge.net Logo

Does RPy works in Windows or Mac?

Yes, versions since 0.3 support Windows and Mac. RPy is included in the Fink project, which ports Unix software to Mac.

When I try to import the module in Python with 'from rpy import *', I get an error:
    ImportError: libR.so: cannot open shared object
    file: No such file or directory

You need to ensure that libR.so is available to RPy. First, ensure that R has been compiled as a shared library. To compile R as a shared library, perform follow this steps:

    (go to the R source directory)
    make distclean
    ./configure --enable-R-shlib
    make
    make install
During the compilation of RPy, the path to libR.so is included in the RPy shared library. This should allow RPy to find libR.so unless it is moved to a new location, in which case you will need to do one of the following (substitute R_HOME for the directory where R is installed, usually /usr/local/lib/R):
  • make a link to R_HOME/bin/libR.so in /usr/local/lib, or in some other location that your system knows as a standard place for libraries; then run 'ldconfig' as root;
  • or edit /etc/ld.so.conf to add the line 'R_HOME/bin' and run 'ldconfig' as root;
  • or set the environment variable LD_LIBRARY_PATH with
        export LD_LIBRARY_PATH=$LD_LIBRARY_PATH\
               :R_HOME/bin
    
    in your .bashrc (or equivalent).
If these suggestions don't work, try to remove the R source directory, unpack the sources again and then execute the previous instructions. It has been reported that the removing and unpacking may be necessary.

In Windows, when importing RPy, I get:
    ImportError: R.DLL version does not match

Make sure that the R bin directory is in your path. This holds the R.dll that python needs to load for rpy to work. For R version 1.6.1 this path is (by default)

    C:\Program Files\R\rw1061\bin\
For windows 98 or ME it is easier to use the path C:\Progra~1\R\rw1061\bin instead.

Under Windows 2000 and later right click on "My Computer" and select properties. Now click the Advanced tab and select environment variables. Finally edit the path variable under system variables and add

    C:\Program Files\R\rw1061\bin\
to your path. Make sure that all paths are seperated by semi-colons.

All others need to edit the Autoexec.bat file and add a line similar to:

    set PATH=%PATH%;C:\Progra~1\R\rw1061\bin
near the end.

When R object 'foo' changes, the expression r.foo still has the old value. Is this a bug?

It is not a bug (it's a feature :-) ). R objects are cached in a Python dictionary after the first time. This is so in order to assign them the local conversion mode. If you need to retrieve a changing R object, you can use the expression r('foo'), which evaluates in the R interpreter the expression 'foo' and returns its result.

When I load rpy on Unix (Linux, Mac, etc) , I get an error like:
    
    >>> from rpy import *
    Error in gzfile(file, "rb") : invalid `enc" argument
     Error: couldn"t find function "attach"
     Traceback (most recent call last):
       File "", line 1, in ?
       File "/usr/local/lib/python2.3/site-packages/rpy.py", line 
    192, in ?
         r = R()
       File "/usr/local/lib/python2.3/site-packages/rpy.py", line 
    174, in __init__
         self.TRUE = self.__getitem__("T")
       File "/usr/local/lib/python2.3/site-packages/rpy.py", line 185, in
    __getitem__
         obj = self.__dict__[name] = self.__dict__.get(name, 
    _rpy.get(name))
     rpy.RException: Object "T" not found
     >>>
    

It appears that this is caused by a problem in the build of rpy. Rebuilding and installing via:

    python setup.py build -f -g
    python install
seems to resolve the problem.

On windows, I get an error like:
Warning message:
unable to load shared library 'C:\Program 
Files\R\rw2011/modules/lapack.dll':
   LoadLibrary failure:  The specified module could not be found.

Traceback (most recent call last):
   File "C:/TEMP/Manuel_Metz_2004_11_22.py", line 9, in -toplevel-
     para = rpy.r.summary(fit) #Here I get an error
RException: Error in La.chol2inv(x, size) : lapack routines cannot be loaded

This error occurs if you don't have the R 'bin' directory in your path. Under Windows 2000 right click on "My Computer" and select properties. Now click the Advanced tab and select environment variables. Finally edit the path variable under system variables and add

    C:\Program Files\R\rw2011\bin\
to your path. Make sure that all paths are seperated by semi-colons.

All others need to edit the Autoexec.bat file and add a line similar to:

    set PATH=%PATH%;C:\Progra~1\R\rw2011\bin
near the end. Note that you should replace the '2011', which is appropriate for R version 2.1.1, with the appropriate number for the R version you have installed.

News

Last update on 10-2012