15

I am trying to import rpy2 into python and I am getting this error:

RuntimeError: The R home directory could not be determined.
Try to install R <https://www.r-project.org/>,
set the R_HOME environment variable to the R home directory, or
add the directory of the R interpreter to the PATH environment variable.

I am completely lost here as I have no idea what this is telling me. I tried to search up how to set the environment variable and couldn't find anything detailed enough that was helpful for me. I would appreciate it if the answer could be very straightforward as I am just a newbie. I am running OSX 10.11.

Thank you (my first post, I apologize if I overlooked any rules in posting)

Jerry W
  • 185
  • 1
  • 2
  • 10
  • 2
    I tried to set up the R_HOME but get this error - ``WARNING: ignoring environment value of R_HOME /usr/local/lib/R`` Did you solve it? – Nielsen Rechia Apr 25 '18 at 20:00

2 Answers2

13

Setting R_HOME this way worked for me

import os
os.environ['R_HOME'] = '/path/to/R'
geecko
  • 141
  • 1
  • 3
10

It is the other way around -- the R in your PATH should know its home:

edd@don:~$ R RHOME
/usr/lib/R
edd@don:~$ 

This echos the last line recommendation -- have your R in the PATH.

On another machine with both R and R-devel, I choose to address the latter under a different name. Still, each knows its HOME:

edd@max:~$ /usr/local/lib/R-devel/bin/R RHOME
/usr/local/lib/R-devel/lib/R
edd@max:~$ R RHOME
/usr/lib/R
edd@max:~$ 
Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • 3
    Ok, so how do I check the directory for my R interpreter and subsequently, how do I add it to PATH? – Jerry W Jul 05 '16 at 04:08
  • 1
    `export PATH=/${PATH}`. Also, it is generally advised to leave OSX's system Python alone. Consider using "homebrew" (and may be also install R with homebrew - things should work out of the box then). – lgautier Jul 05 '16 at 08:57