Rpy2 error wac-a-mole: R_USER not defined
Question: I'm running Python (x,y) 2.7 on windows 7 32 bit and R version 3.1.0. I've
been trying to install Rpy2 and have been getting many errors. I finally found
this site which has pre-compiled python modules for windows
<http://www.lfd.uci.edu/~gohlke/pythonlibs/>, so I downloaded
rpy2‑2.4.2.win32‑py2.7.exe. When I did this and tried

    
    
    import rpy2.robjects as robjects
    

I had an error saying it could not find R_HOME, so I updated my path
variables. This was fixed, but then I got an error saying it could not find
R_USER. Once again, I updated my PYTHONPATH variables based on SO responses.
This didn't work, and so I'm stuck. I've updated my PYTHONPATH both inside
Spyder and also in my system variables, but still no luck. Does anyone know
what could be going on? This is the error I get:

    
    
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      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.
    

This is what my PYTHONPATH includes:

    
    
    C:\Python27\Lib\site-packages\rpy2;C:\Program Files\R\R-3.1.0\bin\i386;C:\Python27\Lib\site-packages\rpy2\robjects
    

This is what my PATH includes:

    
    
    C:\Python27\Lib\site-packages\PyQt4;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;c:\Program Files\Intel\DMIX;C:\Program Files\Intel\Services\IPT\;C:\Python27;C:\Python27\DLLs;C:\Python27\Scripts;C:\Python27\Lib\site-packages\vtk;C:\Python27\gnuplot\binary;C:\Program Files\pythonxy\SciTE-3.1.0;C:\Program Files\pythonxy\console;C:\MinGW32-xy\bin;C:\Program Files\R\R-3.1.0\bin;C:\MinGW32-xy\mingw32\bin;C:\MinGW32-xy\bin
    

Thanks for any help you can provide!


Answer: You need to set the `R_USER` environment variable, e.g. to the username of the
Windows account you use. See also this quote from [this
link](https://bitbucket.org/lgautier/rpy2/issue/95/automagic-settings-for-
windows):

> 1) Add the path to R.dll to my PATH variable (I went to the 32-bit
> directory) 2) Add an environment variable R_HOME (C:\Program
> Files\R\R-2.12.1 for me) 3) Add an environment variable R_USER (simply my
> username in Windows).

