I'm trying to run a Python program that uses rpy2. Installation was successful, I think. But when I try to run it, I get the following error:
Traceback (most recent call last):
File "", line 1, in runfile('C:/Users/(file location)', wdir='C:/Users/(file location)')
File "C:\Users(my name)\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile execfile(filename, namespace)
File "C:\Users(my name)\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/(file location)", line 5, in from rpy2.robjects import r
File "C:\Users(my name)\Anaconda3\lib\site-packages\rpy2\robjects__init__.py", line 19, in from rpy2.robjects.robject import RObjectMixin, RObject
File "C:\Users(my name)\Anaconda3\lib\site-packages\rpy2\robjects\robject.py", line 6, in rpy2.rinterface.initr()
File "C:\Users(my name)\Anaconda3\lib\site-packages\rpy2\rinterface__init__.py", line 208, in initr _initr(r_preservehash=r_preservehash)
RuntimeError: R_USER not defined.
I found a question that addresses just this problem: Rpy2 error wac-a-mole: R_USER not defined. The answer says to set the R_user environment variable. Unfortunately, I don't know how to do that; I hadn't even heard of an environment variable before until this. I followed the only lead I saw: the link in the answer. That led to a webpage with two downloadable python files: set_Rvars32_win32.py and setup.py. I tried running both, but they both yield an error. Here is the traceback for set_Ravars32_win32.py
Traceback (most recent call last):
File "", line 1, in runfile('C:/Users/(my name)/Anaconda3/set_Rvars_win32.py', wdir='C:/Users/Jin/Anaconda3')
File "C:\Users(my name)\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile execfile(filename, namespace)
File "C:\Users(my name)\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/(my name)/Anaconda3/set_Rvars_win32.py", line 4, in import _winreg
ModuleNotFoundError: No module named '_winreg'
setup.py yields the same error and the same traceback sequence (except of course the file is C:/Users/(my name)/Anaconda3/setup.py)
I then tried running the Anaconda Prompt (Anaconda3).
pip install _winreg yields
ERROR: Invalid requirement: '_winreg'
pip install winreg yields
Collecting winreg
ERROR: Could not find a version that satisfies the requirement winreg (from versions: none)
ERROR: No matching distribution found for winreg
Am I on the right track? Or is there an easier way to set environment variables?
Thanks