1

I'm having a weird issue with R.

Basically, I am following this analysis pipeline in order to understand how it works. At some point (right after the first introductory paragraph, the last few lines of the history) I find this piece of code:

#--- clustering ---#
for (n in names(all.sce)) {
    g <- buildSNNGraph(all.sce[[n]], k=10, use.dimred='PCA')
    clust <- igraph::cluster_walktrap(g)$membership
    colLabels(all.sce[[n]])  <- factor(clust)
}

that calls this function colLabels which throws a very weird error:

Error in colLabels(allEnsembl[[n]]) <- factor(clust) :    cant find the
function "colLabels<-"

Now, since I am working with a specific kind of data, i.e. single cell data (bioinformatics here), I've looked into this function and it seems to be part of this package called SingleCellExperiment, which I can load successfully before launching the above piece of code.

Once I encountered the error I looked into the R help which can't actually find anything:

> help(colLabels)

No documentation for 'colLabels' in specified packages and libraries: you could try '??colLabels'

> ??colLabels

No vignettes or demos or help files found with alias or concept or title matching 'colLabels' using fuzzy matching.

Problem is...why does the error point to a function (apparently) called colLabels<-?

EDIT: other functions from the mentioned package, i.e. SingleCellExperiment, work and help pages are available.

EDIT 2: I've imported the required library. I also looked into the version I've installed and it seems to be an issue related to the versions. Using sessionInfo() R tells me I've version 1.8.0 which fits with what stated in the Bioconductor website. The packages version available and also the pdf documentation refers to 1.8.0. BUT I've noticed that in the previous link I've attached I was referring to a development version...probably I need to install it (?)

EDIT 3: ok, I have other issues now. The one in the question was an issue related to the package version since the official SingleCellExperiment was 1.8.0 while the doc I found was related to 1.9.3 which was a development version. Once installed, the help for the function works, but the function itself do not. sessionInfo() now states that I have the version 1.9.3 but other functions do not work anymore so, I dont know.

gabt
  • 668
  • 1
  • 6
  • 20
  • I don't see what's weird. It looks like a simple error: that function is not available. Maybe it was never exported, maybe it wasn't imported. – user2554330 Apr 16 '20 at 09:41
  • well, to me, the weird thing is that R is looking for a function called `colLabels<-` which is something I've never seen before. Also...I have re-installed the package but still it does not work – gabt Apr 16 '20 at 09:51
  • also...what do you mean with: "it was never exported", if I may ask? – gabt Apr 16 '20 at 09:53
  • could you check the if `colLables` in the list of available functions in the imported `SingleCellExperiment` package? Use something like this: https://stackoverflow.com/questions/20535247/how-to-find-all-functions-in-an-r-package – oszkar Apr 16 '20 at 10:26
  • @oszkar it looks like it's not there. But it may be a problem of the package version as mentioned in the EDIT 2 – gabt Apr 16 '20 at 10:28
  • @gabt a our edit3: have you uninstalled the previous version properly? And I think that is do not related to the original question, so maybe it would be better to ask it in a separate question. – oszkar Apr 16 '20 at 12:27
  • @oszkar well I'm trying several options and, yes, I believe it was properly uninstalled but still I'm having issues. Let's see if I will come up with something! – gabt Apr 16 '20 at 12:39

2 Answers2

2

This is the default R behaviour.

If you call a not imported or non-existing function, the error message looks like:

> non_existing_function(x)
Error in non_existing_function(x) : 
  could not find function "non_existing_function"

If you call a not imported or non-existing function together with an assignment operator, the error message looks like:

> non_existing_function(x) <- y
Error in non_existing_function(x) <- y : 
  could not find function "non_existing_function<-"

You have to import the SingleCellExperiment package to be able to use colLabels:

library(SingleCellExperiment)

Update: You definitely have to use the dev version (1.9.3). If you check the manual for the current stable (1.8.0), there is no function colLables there, but there is in the manual for dev version (1.9.3).

oszkar
  • 865
  • 5
  • 21
  • I've imported the library. I edited the question to make this point more clear. Anyway, I didn't know about the "non_existing_function<-" error! – gabt Apr 16 '20 at 10:20
  • In R everything is a function. See [section 3.4.4 of the language definition](https://cran.r-project.org/doc/manuals/r-release/R-lang.html#Subset-assignment) for what the parser does here. – Roland Apr 16 '20 at 10:56
2

The colLabels function was only added in version 1.9.3. This will come out with the next Bioconductor release at the end of this month, see here. In the meantime, you can either:

Install R 4.0.0 and start using BioC-devel to get access to 1.9.3, or Just get and set values from sce$label, which does the same thing.

These are quotes from Aaron Lun's (SingleCellExperiment package developper) Git Memory.

JulverN
  • 121
  • 5