Open Obihoernchen80 opened 1 month ago
Hi, thanks for reporting. I tried but can't reproduce locally. The import("rpy2.robjects")
command succeeds without error for me:
> reticulate::import("rpy2.robjects")
/Users/tomasz/.virtualenvs/r-reticulate/lib/python3.10/site-packages/rpy2/rinterface_lib/embedded.py:276: UserWarning: R was initialized outside of rpy2 (R_NilValue != NULL). Trying to use it nevertheless.
warnings.warn(msg)
R was initialized outside of rpy2 (R_NilValue != NULL). Trying to use it nevertheless.
Module(rpy2.robjects)
Do you perhaps have any custom Makevars
setup?
Do you perhaps have any custom
Makevars
setup?
No.
From what I've gathered it seems to be windows issue and from your paths, I'd say you are running Linux?
I can also reproduce this on Windows. Here's what's on the stack after plugging WinDbg
This is all running threads:
This is the R main thread:
This is the other thread where reticulate appears:
It seems the error is coming from here: https://github.com/wch/r-source/blob/b12ffba7584825d6b11bba8b7dbad084a74c1c20/src/main/memory.c#L1742
I'm not a Windows machine presently, but reading the source code, it seems that rpy2 is trying to initialize R when R is already initialized.
It seems that Rf_initEmbeddedR()
is called by rpy2, but only on Windows, from _initr_win32()
which is set on module import:
https://github.com/rpy2/rpy2/blob/ae74c26deca603786acfe0bdb03433bfc74975fc/rpy2/rinterface.py#L41-L43
That, calls openrlib.rlib.Rf_initEmbeddedR
https://github.com/rpy2/rpy2/blob/ae74c26deca603786acfe0bdb03433bfc74975fc/rpy2/rinterface_lib/embedded_mswin.py#L48
Which leads to the error where the R symbol table is being attempted to be initialized twice. The stacktrace @dfalbel posted confirms that we have an Rf_initEmbeddedR
call in the stack, after the R main loop is already running.
It's not clear to me why rpy2 is attempting to initialize R. The other output from rpy2 indicates that some parts of rpy2 are correctly detecting that R is already initialized. A Python stacktrace from the _initr_win32()
call would be the next step.
@lgautier Do you know why rpy2 might be attempting to initialize R when running embedded under reticulate on Windows?
Describe the issue or bug and how to reproduce
This works in python console:
This fails in R console:
reticulate::import("rpy2.robjects")
The following message is infinitely printed
****found a symbol with attributes
Same issue, reported on rpy2 github:
https://github.com/rpy2/rpy2/issues/942
Package versions
windows 10 64bit R core : 4.3.0 reticulate: 1.38.0 rpy2: 3.5.16 python: 3.10.11