pythonrjupyter-notebookrpy2seurat

R kernel crashes while loading R package using rpy2


First of all, I’m new to rpy2 / jupyter so please don’t judge me if this isn’t the correct place to ask my question.

I am trying to set up an integrated workflow for data analysis using R and Python and I encounter the following error:

I am on Ubuntu 19.04. running a conda environment using Jupyter 1.0.0, Python 3.7.4, R 3.5.1, r-irkernel 1.0.2 and rpy2 3.1.0 and I installed the R-package Seurat through R.

When I create a Jupyter notebook using the R-kernel, I can load Seurat with library(Seurat) just fine.

I can also use R code in python using rpy2 and the rmagic such as:

%load_ext rpy2.ipython
%%R
data(allen, package = 'scRNAseq')
adata_allen <- as(allen, 'SingleCellExperiment')

However when I try to load Seurat using rpy2 the kernel crashes:

%%R
library(Seurat)

And I get the following message:

Kernel Restarting
The kernel appears to have died. It will restart automatically

Jupyter gives the following message in the command line:

[I 16:39:01.388 NotebookApp] KernelRestarter: restarting kernel (1/5), keep random ports
kernel 23284ec0-63d5-4b61-9ffa-b52d19851eab restarted

Note that other libraries such as library(dplyr) load just fine using rpy2.

My complete conda environment can be found in the attached text file.

I just can’t seem to figure out what is causing the problem. Is there a way to get a more verbose error message from Jupyter?

Your help would be greatly appreciated!

Regards Felix


Solution

  • **This is an edit of the original answer - the segfault should not longer occur. **

    The R package Seurat is using an other R package called reticulate, providing a bridge to Python from R.

    A issue with the Python GIL being release by cffi on the rpy2 side, and the reticulate side not ensuring that the GIL was acquired caused a segfault for a long time. However, current (2023) versions of rpy2 and reticulate should work together.