Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 247
fkoegel Avatar asked Jul 23 '26 06:07

fkoegel


1 Answers

I had the same problem and I am also using R and python with a Jupyter notebook in docker.

I solved the Kernel crash issue by starting my notebook or Python code with this:

import os \
os.environ['R_HOME'] = '/usr/lib/R'

/usr/lib/R is where I have my system's R installation and libraries, and should be an R version needed by rpy2. Hope this helps.

like image 130
Luis Peraza Avatar answered Jul 24 '26 22:07

Luis Peraza



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!