I'm trying to load the SoupX library from R using %%R R magic but I'm encountering a dev.off() error:
----> 1 get_ipython().run_cell_magic('R', '', 'library(SoupX)\n#Loads R packages required for ambient RNA correction\n')
-> 2478 result = fn(*args, **kwargs)
--> 981 ro.r('dev.off()')
--> 501 res, visible = rinterface.evalr_expr_with_visible( # type: ignore
502 r_expr
503 )
RRuntimeError: Error in dev.off() : cannot shut down device 1 (the null device)`
It loads normally in R, the problem seems to be related to Jupyter Notebook
I loaded these modules
import rpy2.rinterface_lib.callbacks as rcb
import rpy2.robjects as ro
rcb.logger.setLevel(logging.ERROR)
ro.pandas2ri.activate()
anndata2ri.activate()
%load_ext rpy2.ipython
and tried running:
%%R
library(SoupX)
Has anyone encountered a similar issue with dev.off() in Jupyter Notebook? Are there specific considerations for using graphical devices in Jupyter Notebook with the %%R magic command?