I'm trying to call an R function from python using rpy2 in a Jupyter notebook within VScode. This is being run through anaconda (required by company...). The rpy2 package was working, up until I had to reinstall my R versions due to some corruption. After getting new R versions (4.2.3), the rpy2 package doesn't seem to want to import.
When I go to import rpy2.objects I get the follow errors:
R[write to console]: Error in gettext(fmt, domain = domain, trim = trim) :
3 arguments passed to .Internal(gettext) which requires 2
RRuntimeError Traceback (most recent call last)
Cell In[12], line 1
----> 1 import rpy2.robjects as ro
File c:\ProgramData\Anaconda3\envs\dblock\lib\site-packages\rpy2\robjects\__init__.py:19
16 import rpy2.rlike.container as rlc
18 from rpy2.robjects.robject import RObjectMixin, RObject
---> 19 import rpy2.robjects.functions
20 from rpy2.robjects.environments import (Environment,
21 local_context)
22 from rpy2.robjects.methods import methods_env
File c:\ProgramData\Anaconda3\envs\dblock\lib\site-packages\rpy2\robjects\functions.py:12
10 import rpy2.rinterface as rinterface
11 import rpy2.rinterface_lib.sexp
---> 12 from rpy2.robjects import help
13 from rpy2.robjects import conversion
14 from rpy2.robjects.vectors import Vector
File c:\ProgramData\Anaconda3\envs\dblock\lib\site-packages\rpy2\robjects\help.py:45
41 ok = _eval(expr)
42 return ok
---> 45 quiet_require('tools')
46 _get_namespace = rinterface.baseenv['getNamespace']
...
818 return res
RRuntimeError: Error in gettext(fmt, domain = domain, trim = trim) :
3 arguments passed to .Internal(gettext) which requires 2
I've tried reinstalling all the packages, removing R and reinstalling that to an older version, and a couple things on forums (first thing, second thing.
When running rpy2.situation I get the following output:
(dblock) C:\Users\NAME>python -m rpy2.situation
rpy2 version:
3.5.10
Python version:
3.8.15 | packaged by conda-forge | (default, Nov 22 2022, 08:42:03) [MSC v.1929 64 bit (AMD64)]
Looking for R's HOME:
Environment variable R_HOME: None
InstallPath in the registry: C:\Users\NAME\Documents\R-4.1.0
Environment variable R_USER: None
Environment variable R_LIBS_USER: None
R version:
In the PATH: R version 4.1.0 (2021-05-18) -- "Camp Pontanezen"
Loading R library from rpy2: OK
Additional directories to load R packages from:
None
C extension compilation:
'sh' is not recognized as an internal or external command,
operable program or batch file.
Warning: Unable to get R compilation flags.
Directory for the R shared library:
'sh' is not recognized as an internal or external command,
operable program or batch file.
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\envs\dblock\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\ProgramData\Anaconda3\envs\dblock\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\ProgramData\Anaconda3\envs\dblock\lib\site-packages\rpy2\situation.py", line 505, in <module>
for row in iter_info():
File "C:\ProgramData\Anaconda3\envs\dblock\lib\site-packages\rpy2\situation.py", line 463, in iter_info
yield get_r_libnn(r_home)
File "C:\ProgramData\Anaconda3\envs\dblock\lib\site-packages\rpy2\situation.py", line 272, in get_r_libnn
return _get_r_cmd_config(r_home, 'LIBnn',
File "C:\ProgramData\Anaconda3\envs\dblock\lib\site-packages\rpy2\situation.py", line 255, in _get_r_cmd_config
output = subprocess.check_output(
File "C:\ProgramData\Anaconda3\envs\dblock\lib\subprocess.py", line 415, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "C:\ProgramData\Anaconda3\envs\dblock\lib\subprocess.py", line 516, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '('C:\\Users\\NAME\\Documents\\R-4.1.0\\bin\\x64\\R', 'CMD', 'config', 'LIBnn')' returned non-zero exit status 1.
It lists the version of R I was using previously (4.1.0), but I'm not able to run this in the jupyter notebook.
I have also tried running this through the anaconda prompt which does seem to work. It is able to import the rpy2.robjects fine, wihtout errors after specifying the R-HOME in the environment.
Edit/Update: After moving the directory everything was working for some time. Now, the kernal has broken again and doesn't work.
I get the error:
R[write to console]: Error in gettext(fmt, domain = domain, trim = trim) :
3 arguments passed to .Internal(gettext) which requires 2
Output exceeds the size limit. Open the full output data in a text editor---------------------------------------------------------------------------
RRuntimeError Traceback (most recent call last)
Cell In[5], line 16
13 import cx_Oracle
15 # R Packages
---> 16 import rpy2.robjects as ro
17 import rpy2
18 import rpy2.robjects as ro
File c:\ProgramData\Anaconda3\envs\dblock\lib\site-packages\rpy2\robjects\__init__.py:19
16 import rpy2.rlike.container as rlc
18 from rpy2.robjects.robject import RObjectMixin, RObject
---> 19 import rpy2.robjects.functions
20 from rpy2.robjects.environments import (Environment,
21 local_context)
22 from rpy2.robjects.methods import methods_env
File c:\ProgramData\Anaconda3\envs\dblock\lib\site-packages\rpy2\robjects\functions.py:12
10 import rpy2.rinterface as rinterface
11 import rpy2.rinterface_lib.sexp
---> 12 from rpy2.robjects import help
13 from rpy2.robjects import conversion
14 from rpy2.robjects.vectors import Vector
File c:\ProgramData\Anaconda3\envs\dblock\lib\site-packages\rpy2\robjects\help.py:45
...
818 return res
RRuntimeError: Error in gettext(fmt, domain = domain, trim = trim) :
3 arguments passed to .Internal(gettext) which requires 2