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 on 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.