I was using Seurat v3.2 and I did most of my single-cell analysis using this version. But today I started working on another dataset and there I encountered this error
[[<- defined for objects of type "S4" only for subclasses of environment. I googled about it and I got to know that this is something to do with the Seurat version. This GitHub issue suggesting that if we update the Seurat version, it should fix this problem.
Well, with this lead I started googling about how to update the Seurat and eventually R version using conda. Here you may have a question, why specifically using conda? The reason is, I am a student and working on the university server, thus I do not have ample privilege to install a tool/software directly using system command.
Back to the story, I googled about how to update the R version using conda and I ended up with the possible solutions (also reported on StackOverflow). Somewhere it was mentioned that if we uninstall conda r-base using the
conda uninstall r-base command and re-install the same, it should fix the problem. Well, I would say this could be a nice trick to resolve such issues. I mean simply, uninstall conda r-base and install an updated version (
R>=4.0) in one environment and
R3.2 in another. But unfortunately, in my case, it was not an optimal choice. Because I am working on different projects and to deal with them I have already configured other R packages. So, you see? it's not only about Seurat, and I can not simply mess up with my R environment, just to update the Seurat version, right?
Therefore, again, I started communicating with google about updating R and tried the solutions described above. While trying other solutions I realized that it is something to do with conda channels that I am using. Because here, they have clearly mentioned the R version but when I was trying to install R4.0 it was not going through the
conda-forge channel, instead, it was redirected to a different channel. In fact, the same channel (checked with
conda info command) that I had set long back to install R3.2.
With the help of google, finally, I found the solution.
Here are the commands that I had used to resolve this issue:
An updated R version (>=4.0) is available through the conda-forge channel, so first add the channel.
conda config --add channels conda-forge
We are going to install R through conda-forge and not through the default channel, so we need to set its priority over the default channel.
conda config --set channel_priority strict
NOTE: You can undo this change by setting strict priority to the default channel as described here.
Check whether an updated R version is added in the conda search space or not.
conda search r-base
Now, it is always a good practice (recommoned here) to create a new conda environment, which will help to debug the package-specific and compatibility issues without disrupting the base environment.
conda create -n seurat4 python=3.6
Let's activate the newly create conda environment.
conda activate seurat4
And finally install the R package.
conda install -c conda-forge r-base
I hope this will help someone in the future and save their time.
Good tutorial. As a shortcut to create an environment with seurat v4 you can do
conda create -n seurat -c conda-forge -c bioconda r-seurat=4*. The environment can be activated with
conda activate seurat, and updated with
conda update -c conda-forge -c bioconda -n seurat --all.
Hi Nitin, I tried to install the latest R (version 4.1.0) using conda following your tutorial. The installation is success. But when I tried to use it, I got an error said
Segmentation fault (core dumped). I tried to google the error but still don't understand what is going wrong. Do you have any idea about this error?
Do you mean, you are trying to run
Rand getting the error
segmentation fault (core dumped)OR running some command on the
Rinterpreter and getting this error?
Maybe creating another environment would help (You can create an environment suggested by @repolicastro in the comment above ).
You can use the above code also to get Jupyter notebooks in Anaconda running the latest R. Look at the following code below. You need to fill in a name of your environment for "your_name_here" and choose version numbers for python and R:
Now, install RStudio in your environment via Anaconda.
In RStudio, write in the R console: