Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Questions on use of setGenericImplicit() #3

Open
PeteHaitch opened this issue May 21, 2018 · 0 comments
Open

Questions on use of setGenericImplicit() #3

PeteHaitch opened this issue May 21, 2018 · 0 comments
Labels

Comments

@PeteHaitch
Copy link
Collaborator

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?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant