Search code examples
rseurat

Why does FindNeighbor from Seurat give "'CsparseMatrix_validate' not found" error?


This is the code that I want to run:

Aldh1l1.neg_Atp1b2.pos_new <- FindNeighbors(Aldh1l1.neg_Atp1b2.pos_new, dims = 1:10)

But it doesn't work due to this error:

Error in validityMethod(as(object, superClass)) : 
  object 'CsparseMatrix_validate' not found

I have already reinstalled the Seurat and Matrix packages several times. I have even reinstalled RStudio once.

The call stack looks like this:

> traceback()
15: validityMethod(as(object, superClass))
14: isTRUE(x)
13: anyStrings(validityMethod(as(object, superClass)))
12: validObject(.Object)
11: .nextMethod(.Object = .Object, ... = ...)
10: callNextMethod()
9: initialize(value, ...)
8: initialize(value, ...)
7: new(Class = "Graph", i = c(0L, 62L, { ... TRUNCATED ... }
6: do.call(what = "new", args = object.list)
5: UpdateSlots(object = object)
4: `DefaultAssay<-.Graph`(object = `*tmp*`, value = assay)
3: `DefaultAssay<-`(object = `*tmp*`, value = assay)
2: FindNeighbors.Seurat(Aldh1l1.neg_Atp1b2.pos_new, dims = 1:10)
1: FindNeighbors(Aldh1l1.neg_Atp1b2.pos_new, dims = 1:10)

Solution

  • The underlying issues are discussed in this thread on the R-devel mailing list, from September 2022.

    CsparseMatrix_validate was defined in Matrix 1.5-3 to replace the existing validity method for virtual class CsparseMatrix. The problem is that some packages built under Matrix 1.5-3 (or newer) cache the validity method in their namespace, but not the definition of CsparseMatrix_validate.

    When the cached method is called, CsparseMatrix_validate must be found in whatever version of Matrix that you have installed. If that version is older than 1.5-3, then the symbol is not found, and the result is the error that you see.

    To solve it for all users, the maintainer of the culprit package should put Matrix (>= 1.5-3) in their package's DESCRIPTION file under Imports or Depends.

    Until that happens, it should suffice for individual users to install Matrix 1.5-3 (or newer):

    > install.packages("Matrix", repos = "https://cran.r-project.org/")
    > packageVersion("Matrix")
    [1] '1.5.3'
    

    If that doesn't work, then we'll need more details about your setup (library paths, etc.).