Closed hpages closed 5 months ago
The reason why I decided to skip the deprecation process and immediately align with sparseMatrixStats
with matrixStats
is that center
argument of the wrong length never worked in sparseMatrixStats
:
# Code using an old sparseMatrixStats version
library(Matrix)
mat <- matrix(1:12, nrow = 4)
sp_mat <- as(mat, "dgCMatrix")
matrixStats::colVars(mat, center = 5)
#> Warning: Argument 'center' should be of the same length as number of columns of
#> 'x'. Use of a scalar value is deprecated: 1 != 3
#> [1] 10.000000 4.666667 42.000000
sparseMatrixStats::colVars(sp_mat, center= 5)
#> [1] 10.0000 58.0000 148.6667
Created on 2024-04-18 with reprex v2.0.2
The original code simply never checked that the center vector had the right length. I considered this a bug and decided it was easiest to just throw an error if the argument lengths didn't match.
To your main point:
I see no reason why this shouldn't work anymore: ...
MatrixGenerics::colVars(m, center=0)
I think it is important to keep MatrixGenerics
aligned with matrixStats
to avoid user confusion. And as it was me who decided to copy Henrik's API, I will follow his decisions on how to evolve the API. For MatrixGenerics
, I think that it should try to smooth over conflicts that arise due to the different release models of CRAN and Bioconductor, but should otherwise stay aligned with matrixStats
.
The center=0
case is a little bit special though. It has been used for a while in DelayedArray and the package has been relying on it to be supported by sparseMatrixStats. Which it did! And with no deprecation warning:
sparseMatrixStats::colVars(as(mat, "dgCMatrix"), center=0)
# [1] 10.0000 58.0000 148.6667
If handling of scalar center in the != 0
case was broken, it should be fixed. But again, it's not a good idea to make this kind of changes without going to a deprecation/defunct cycle first. We're also very close to a new BioC release which makes things even worse.
I see no reason why this shouldn't work anymore:
The proposed patch makes it work again:
and so is consistent with SparseArray:
and also consistent with the treatment of
center
in DelayedArray.It also fixes some loopholes in matrixStats check of user input. For example:
In comparison going thru
MatrixGenerics::normarg_center()
guarantees a sanecenter
value, and, if not, it produces a straightforward error message:Note that the reason this patch exports
normarg_center()
is because I want to reuse it in a PR that I'm about to submit for DelayedMatrixStats (see https://github.com/Bioconductor/DelayedArray/issues/115). I will also probably start using it in SparseArray and DelayedArray for consistent argument checking.H.
P.S.: @const-ae It seems that you've recently aligned treatment of
center
in sparseMatrixStats with matrixStats. With the latest sparseMatrixStats (version 1.15.1, in BioC 3.19):2 problems with this change:
This means that code around that relies on this will suddenly break with no advance notification to give people a chance to fix their code.