Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R_HOME Error with rpy2

I know there are quite a few posts on getting up and running with rpy2 on windows 7 32 bit. I have referenced a good number of them and attempted their solutions, including the use of PypeR.

I dont explicitly have a R_HOME variable set in my path, but per this question, I confirmed that R is in my PATH (I can type R at the command line and get R to run) and even copied all of the files from the i386 folder to the parent bin folder.

My issue is pasted below. Any thoughts?

In [5]: from rpy2 import robjects
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-5-1f019d00d232> in <module>()
----> 1 from rpy2 import robjects

C:\Anaconda\lib\site-packages\rpy2\robjects\__init__.py in <module>()
     16 import rpy2.rlike.container as rlc
     17
---> 18 from rpy2.robjects.robject import RObjectMixin, RObject
     19 from rpy2.robjects.vectors import *
     20 from rpy2.robjects.functions import Function, SignatureTranslatedFunction

C:\Anaconda\lib\site-packages\rpy2\robjects\robject.py in <module>()
      3 import rpy2.rinterface
      4
----> 5 rpy2.rinterface.initr()
      6
      7 import conversion

RuntimeError: R_HOME not defined.
like image 320
Btibert3 Avatar asked Jul 10 '13 14:07

Btibert3


People also ask

What is R_home?

The R home directory is the top-level directory of the R installation being run. The R home directory is often referred to as R_HOME , and is the value of an environment variable of that name in an R session. It can be found outside an R session by R RHOME .

What is rpy2 package?

rpy2 is an interface to R running embedded in a Python process.

How do I install rpy2 on Windows?

Open a cmd window (as Administrator) in the . whl's download dir. Set R_USER env var to current username: set R_USER=%USERNAME% python -m pip install rpy2‑2.9.


1 Answers

I confirm this issue is related to R_HOME variable not defined.

In my opinion, all of these issues are caused because the developers of rpy2 package haven't documented properly the requirements of their software:

  • Install R
  • Create R_HOME system variable
  • Add R_HOME\bin to the PATH, in order to execute R from python
  • Add R_HOME\bin\x64 to the PATH, in order to load R.dll
  • Install package tzlocal
like image 93
Pablo Avatar answered Sep 30 '22 15:09

Pablo