Skip to content

Questions on use of setGenericImplicit() #3

@PeteHaitch

Description

@PeteHaitch

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.,

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 restore be TRUE (the default) or FALSE in setGenericImplicit()?
  • Should the appropriate matrixStats function (or function from other package, as needed) be used in useAsDefault argument of setGeneric()?
  • Is having matrixStats in Suggests and making its use conditional on it being available the right design?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions