0

My thoughts:
I don't know if this is a conda-problem or an rpy-problem.

Background:
I'm trying to get rpy to run in jupyter/python.

Here is what I am using:

  • MS Windows 11 Pro
  • Anaconda 22.9.0
  • Python 3.7.16
  • R-base 3.6.1

I also have installed a couple of helper packages:

  • numpy version: 1.23.5
  • scipy version: 1.10.0
  • opencv version: 4.6.0
  • matplotlib version: 3.6.2

I installed rpy2 version 2.9.4

When I execute the following code:

import rpy2
import rpy2.situation
for row in rpy2.situation.iter_info():
    print(row)

I get the following output:

rpy2 version:
3.5.11
Python version:
3.9.16 (main, Jan 11 2023, 16:16:36) [MSC v.1916 64 bit (AMD64)]
Looking for R's HOME:
    Environment variable R_HOME: None
    InstallPath in the registry: C:\Program Files\R\R-4.2.2
    Environment variable R_USER: None
    Environment variable R_LIBS_USER: None
R version:
    In the PATH: R version 4.1.3 (2022-03-10) -- "One Push-Up"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
https://www.gnu.org/licenses/.
    Loading R library from rpy2: OK
Additional directories to load R packages from:
None
C extension compilation:
    Warning: Unable to get R compilation flags.
Directory for the R shared library:

At this point it gives me a long string of errors that starts with this:

---------------------------------------------------------------------------
CalledProcessError                        Traceback (most recent call last)
Cell In[14], line 5
      2 import rpy2
      4 import rpy2.situation
----> 5 for row in rpy2.situation.iter_info():
      6     print(row)

And ends with this:

File c:\Users\username\.conda\envs\this_env_name\lib\subprocess.py:528, in run(input, capture_output, timeout, check, *popenargs, **kwargs)
    526     retcode = process.poll()
    527     if check and retcode:
--> 528         raise CalledProcessError(retcode, process.args,
    529                                  output=stdout, stderr=stderr)
    530 return CompletedProcess(process.args, retcode, stdout, stderr)

CalledProcessError: Command '('C:\\Program Files\\R\\R-4.2.2\\bin\\x64\\R', 'CMD', 'config', 'LIBnn')' returned non-zero exit status 1.

When I try to run this:

import rpy2.robjects

The following is the first bit and last bit of the errors produced.

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[16], line 4
      1 #
      2 import rpy2
----> 4 import rpy2.robjects


File c:\Users\username\.conda\envs\this_env_name\lib\site-packages\rpy2\rinterface.py:817, in SexpClosure.__call__(self, *args, **kwargs)
    810     res = rmemory.protect(
    811         openrlib.rlib.R_tryEval(
    812             call_r,
    813             call_context.__sexp__._cdata,
    814             error_occured)
    815     )
    816     if error_occured[0]:
--> 817         raise embedded.RRuntimeError(_rinterface._geterrmessage())
    818 return res

RRuntimeError: Error in gettext(fmt, domain = domain, trim = trim) : 
  3 arguments passed to .Internal(gettext) which requires 2

These did not have a way forward, although the last seemed relevant:

This one says to use pip not conda, but that is a great way to poison conda environments. They can be hacked together but they can also break each other.
How to correctly install rpy2 in python?

Observations:
The R it should be using should be R-3.6 or so, and not R-4.2.2.

Question:
How do I get rpy to run in jupyter without breaking conda? I just want to have python call an r-script, and have it run on objects in the python workspace, then return a new object to the python workspace.

EngrStudent
  • 1,924
  • 31
  • 46

0 Answers0