Closed allisonvuong closed 4 years ago
This seems to be an issue caused by S4 dispatch. You will see the same effect with sparse matrices:
library(Matrix)
n <- rsparsematrix(nrow=10000, ncol=30, density=0.1)
foo(n, j=!logical(ncol(n)))
## Error in object[i, j] : argument "i" is missing, with no default
My guess is that the S4 dispatch mechanism needs to know the class of i
to choose an appropriate method... and i
doesn't exist, leading to the observed error. While S4 dispatch does support missing arguments, it seems that only immediate missingness is supported and it is not propagated from symbols, for example:
library(SingleCellExperiment)
example(SingleCellExperiment, echo=FALSE)
bar <- function(x, i) reducedDim(x, i)
reducedDim(sce) # no problems
bar(sce)
## Error in reducedDim(x, i) : argument "i" is missing, with no default
The immediate fix in your example is to handle the missingness in foo
:
foo <- function(object, i, j) {
args <- list(x=object)
if (!missing(i)) args$i <- i
if (!missing(j)) args$j <- j
do.call("[", args)
}
Not that it really matters because limma can't handle non-ordinary matrices anyway, so you might as well just coerce it to an ordinary matrix and be done with it.
Hi,
Okay, thank you!
Best, Allison
Thanks @LTLA for your help with this. Closing now.
Hi,
Matrix subsetting in base R supports "missing" subsetting arguments, but it seems the DelayedMatrix may not.
For example,
Is it possible to support this? I think packages like
limma::subsetListOfArrays
rely on such subsetting support for subsetting its EList objects.Best, Allison