-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Martin Maechler urged for the use of implicit generics in the earlier email discussion (https://stat.ethz.ch/pipermail/bioc-devel/2017-November/012308.html). Admittedly, I feel like I'm fumbling around a bit here with an incomplete understanding of the methods package, but I have tried to implement this, e.g.,
Lines 41 to 55 in 584e237
| setGeneric( | |
| "rowMedians", | |
| function(x, rows = NULL, cols = NULL, na.rm = FALSE, dim. = dim(x), | |
| ...) standardGeneric("rowMedians"), | |
| signature = "x", | |
| useAsDefault = function(x, rows = NULL, cols = NULL, na.rm = FALSE, | |
| dim. = dim(x), ...) { | |
| if (!requireNamespace("matrixStats", quietly = TRUE)) { | |
| stop("'matrixStats' package required for matrix operations", | |
| call. = FALSE) | |
| } | |
| matrixStats::rowMedians(x, rows = rows, cols = cols, na.rm = na.rm, | |
| dim. = dim., ...) | |
| }) | |
| setGenericImplicit("rowMedians") |
The design pattern of setGeneric() followed by setGenericImplicit() is modelled on ddr; for example, https://github.com/vertica/ddR/blob/f6d7056fded5ae15385d5a16802b67116c30c188/ddR/R/ops.R#L203-L204.
Notably, this is different from that used by BiocGenerics. For example, https://github.com/Bioconductor/BiocGenerics/blob/2f85d3a0de8ab541e55d03ee6ea73d343349a7b8/R/matrix-summary.R#L6
Questions
So the first question is, have I got the use of setGeneric() and/or setGenericImplicit() correct?
Some other questions:
- Should
restorebeTRUE(the default) orFALSEinsetGenericImplicit()? - Should the appropriate matrixStats function (or function from other package, as needed) be used in
useAsDefaultargument ofsetGeneric()? - Is having matrixStats in
Suggestsand making its use conditional on it being available the right design?