Вопрос

I am trying to get rpy2 to work with my standard python setup. For this, I first created a test file to see if everything imports as it should. This is my file rtest.py

import rpy2
from rpy2.robjects import r

print dir(r)

Running these 3 lines from my python shell works just fine, meaning if I open the file in IDLE and run it, it returns a list of strings, as it should.

However, I hit problems when I try to run the same file from my command prompt, I get the following error message:

Traceback (most recent call last):
  File "c:\rtest.py", line 2, in <module>
    from rpy2.robjects import r
  File "C:\Python27\lib\site-packages\rpy2\robjects\__init__.py", line 18, in <module>
    from rpy2.robjects.robject import RObjectMixin, RObject
  File "C:\Python27\lib\site-packages\rpy2\robjects\robject.py", line 5, in <module>
    rpy2.rinterface.initr()
RuntimeError: R_USER not defined.

I have no idea why all of a sudden, python cannot find R_USER. It finds it without a problem in standard IDLE environment.

Это было полезно?

Решение

You may try adding a new environment variables in system variables. Name it R_USER, with its value being the current windows user.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top