Bioconductor / MatrixGenerics

S4 Generic Summary Statistic Functions that Operate on Matrix-Like Objects
https://bioconductor.org/packages/MatrixGenerics
12 stars 1 forks source link

Function only found on second attempt for sparse input #25

Closed const-ae closed 3 years ago

const-ae commented 3 years ago

Hi,

I am trying to use a function from MatrixGenerics using the :: notation. However, it only works on the second attempt:

library(Matrix)
mat <- matrix(1:32, nrow = 8, ncol = 4)
sp_mat <- as(mat, "dgCMatrix")

showMethods(MatrixGenerics::colSums2)
#> Function: colSums2 (package MatrixGenerics)
#> x="ANY"
#> x="matrix_OR_array_OR_table_OR_numeric"
MatrixGenerics::colSums2(mat)
#> [1]  36 100 164 228
showMethods(MatrixGenerics::colSums2)
#> Function: colSums2 (package MatrixGenerics)
#> x="ANY"
#> x="matrix"
#>     (inherited from: x="matrix_OR_array_OR_table_OR_numeric")
#> x="matrix_OR_array_OR_table_OR_numeric"
MatrixGenerics::colSums2(sp_mat)
#> Error in get(as.character(FUN), mode = "function", envir = envir): object 'colSums2' of mode 'function' was not found
showMethods(MatrixGenerics::colSums2)
#> Function: colSums2 (package MatrixGenerics)
#> x="ANY"
#> x="matrix_OR_array_OR_table_OR_numeric"
#> x="xgCMatrix"
MatrixGenerics::colSums2(sp_mat)
#> [1]  36 100 164 228

Created on 2021-06-25 by the reprex package (v2.0.0)

I assume this is related to the whole discussion in https://github.com/Bioconductor/MatrixGenerics/pull/16#issuecomment-707545240. @hpages, do you know what is causing this and what we can do to fix this?

Best, Constantin

const-ae commented 3 years ago

PR #26 fixes the issue (I think), but it would be good if someone could look it over because this was a very deep dive for me into function environments, and my head is still buzzing