Reputation: 121
My goal is to be able to call R from Python 2.7 scripts. I first used easy_install to get the rpy2 module. I then typed the following command into my Spyder console:
from rpy2.robjects.packages import importr
This threw the following 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."
Looks like the R interpreter within rpy2 is not finding R because it's not in the right directory? I had previously downloaded R and RStudio onto my Mac.
I suspect this is a simple fix, and I hoping someone can explain what exactly this error message means, and how I should update either the R_HOME or PATH environment variables (I'm not sure what these are, exactly).
Upvotes: 1
Views: 2053
Reputation: 11545
rpy2 is looking for a executable R
in your PATH
. This means that when opening a terminal windows and entering R
an R terminal should start. Since you are seeing that error message, the odds are that no R is found.
Find where R is, and append that directory to your PATH (e.g., export PATH=/where/R/is:${PATH}
- may be put that to your ~/.bashrc
if starting spyder by clicking on an app icon).
Upvotes: 1