Skip to content
Prev 13459 / 21312 Next

[Bioc-devel] Virtual class for `matrix` and `DelayedArray`? (or better strategy for dealing with them both)

The class union should probably be:

   setClassUnion("matrixOrDelayed", c("matrix", "DelayedMatrix"))

i.e. use DelayedMatrix instead of DelayedArray.

So in addition to the class union and to Stephanie's solution, which
IMO are both valid solutions, you could also go for something like this:

myNewRowMeans <- function(x,...)
{
     if (length(dim(x)) != 2)
         stop("'x' must be a matrix-like object")
     ...
)

that is, just a regular function that checks that 'x' is matrix-like
based on its number of dimensions. If you really want to restrict to
matrix and DelayedMatrix only, replace the test with

     if (!(is.matrix(x) || is(x, "DelayedMatrix")))
         stop("'x' must be a matrix or DelayedMatrix object")

The difference being that now the function will reject matrix-like
objects that are not matrix or DelayedMatrix objects (e.g. a Matrix
derivative from the Matrix package).

Cheers,
H.
On 04/30/2018 09:29 AM, Stephanie M. Gogarten wrote: