Skip to content

Commit

Permalink
Add warning about reticulate. (#863)
Browse files Browse the repository at this point in the history
Add warning about R package reticulate.

The warning is a message (printed through R's `cat()`)
when the R package is loaded.
  • Loading branch information
lgautier committed Apr 2, 2022
1 parent e1be403 commit 13f6685
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions rpy2/robjects/robject.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,30 @@
rpy2.rinterface.initr_simple()


def _add_warn_reticulate_hook():
msg = """
WARNING: While the R package "reticulate" was developped after
Python-R bridges such as rpy2 already existed, it does not
consider that it could be called from a Python process. This
results in a quasi-obligatory segfault when rpy2 is evaluating
R code using reticulate. On the hand, rpy2 is accounting for the
fact that it might already be running embedded in a Python
process. This is why:
- Python -> rpy2 -> R -> reticulate: crashes
- R -> reticulate -> Python -> rpy2: works
The issue with reticulate is tracked here:
https://github.com/rstudio/reticulate/issues/208
"""
rpy2.rinterface.evalr(f"""
setHook(packageEvent("reticulate", "onLoad"),
function(...) cat({repr(msg)}))
""")


_add_warn_reticulate_hook()


class RSlots(object):
""" Attributes of an R object as a Python mapping.
Expand Down

0 comments on commit 13f6685

Please sign in to comment.