3
import rpy2.robjects as ro
     from rpy2.robjects.packages import importr
     from rpy2.robjects import pandas2ri

It raises an error:

ValueError: r_home is None. Try python -m rpy2.situation

I tried googleing but I don't find an answer. I use Linux and python3

Thank you for your help

Noob Programmer
  • 698
  • 2
  • 6
  • 22
  • Where in your code is the ValueError thrown? – Will May 30 '19 at 06:38
  • From the first line and it transfers me to site-packages/rpy2/rinterface_lib/openrlib.py – Noob Programmer May 30 '19 at 06:39
  • have you set R_HOME as an environment variable? – Will May 30 '19 at 06:42
  • What does that mean? – Noob Programmer May 30 '19 at 06:43
  • [here](https://stat.ethz.ch/R-manual/R-devel/library/base/html/Rhome.html) [here](https://stackoverflow.com/questions/12698877/how-to-setup-environment-variable-r-user-to-use-rpy2-in-python) and [here](https://stackoverflow.com/questions/38194876/how-to-set-the-r-home-environment-variable-to-the-r-home-directory) – Will May 30 '19 at 06:45
  • cannot load library '/anaconda2/envs/py3/lib/python3.7/site-packages/lib/libR.so': /anaconda2/envs/py3/lib/python3.7/site-packages/lib/libR.so: cannot open shared object file: No such file or directory it says this now. – Noob Programmer May 30 '19 at 07:07

1 Answers1

3
  1. Search for the path of your R installation (e.g. C:\Program Files\R\R-3.6.1)
  2. Use the following code before importing rpy2:

    import os
    os.environ['R_HOME'] = "C:\Program Files\R\R-3.6.1" #or whereever your R is installed

This works for me (but only temporarily)

Julia
  • 66
  • 9