AlecK
AlecK

Reputation: 21

Importing rpy module into python

I'm trying to import the rpy1.0.3 module for python2.6.6 using:

from rpy import *

and getting this error:

File "C:\Python26\lib\site-packages\rpy.py", line 58, in <module>
    RVERSION = rpy_tools.get_R_VERSION(RHOME)
  File "C:\Python26\lib\site-packages\rpy_tools.py", line 103, in get_R_VERSION
    raise RuntimeError("Couldn't obtain version number from output\n"
RuntimeError: Couldn't obtain version number from output
of `R --version'.

As stated in the rpy documentation I've set up an environmental variable with the file path to my R directory, but it doesnt seem to be able to recognize the version of R (I have 2.9.0 installed). Any thoughts? Thanks

Upvotes: 1

Views: 1560

Answers (1)

mossmatters
mossmatters

Reputation: 31

The setup.py script is calling upon the rpy_tools.py script to gain access to the version number. It searches the output of R --version for a regular expression:

version = re.search(" +([0-9]\.[0-9]\.[0-9])", output)

However, R is now in version 2.13.0, so it won't be able to find a two-digit version number. Replace that line in rpy_tools.py with:

version = re.search(" +([0-9]+\.[0-9]+\.[0-9]+)", output)

You will also need to delete the rpy_tools.pyc file that is created by setup.py

Upvotes: 1

Related Questions