Skip to content
Prev 14589 / 21307 Next

[Bioc-devel] Pushing towards a better home for matrix generics

Hi Martin.

Speed is not the concern: I just did some quick benchmarking and didn't 
observe any significant difference in method dispatch performance after 
doing setGeneric("toto", function(x, a=0, b=0, c=0) 
standardGeneric("toto")) vs doing setGeneric("toto", signature="x", 
function(x, a=0, b=0, c=0) standardGeneric("toto")).

Here is the real concern to me:

Aliases of the form \alias{colSums,dgCMatrix,ANY,ANY-method} are a real 
pain to maintain. It's also a pain for the end user to have to do 
?`colSums,dgCMatrix,ANY,ANY-method` to access the man page for a 
particular method. I know Matrix uses "short" aliases i.e. aliases of 
the form \alias{colSums,dgCMatrix-method} so the user only needs to do 
?`colSums,dgCMatrix-method` but there is a lot of fragility to the 
situation.

Here is why: The exact form that needs to be used for these aliases can 
change anytime depending on what happens in one of the upstream packages 
(not a concern for the Matrix package because no upstream package 
defines colSums methods). More precisely: If all the colSums methods 
defined in the upstream packages and in my own package are defined with 
setMethod statements of the form:

 ?? setMethod("colSums", signature(x="SomeClass"), ...)

then the aliases in the man pages must be of the form 
\alias{colSums,SomeClass-method} and the end user can just do 
?`colSums,SomeClass-method`, which is good. But if **one** upstream 
package decides to use a setMethod statement of the form:

 ? setMethod("colSums", signature(x="SomeClass", na.rm="ANY", 
dims="ANY"), ...)

then the aliases for **all** the colSums methods in **all** the 
downstream packages now must be of the form 
\alias{colSums,SomeOtherClass,ANY,ANY-method}, even if the method for 
SomeOtherClass is defined with signature(x="SomeOtherClass"). Also, as a 
consequence, now the end user has to use the long syntax to access the 
man pages for these methods. And if later the author of the upstream 
package decides to switch back to the setMethod("colSums", 
signature(x="SomeClass"), ...) form, then I have to switch back all the 
aliases in all my downstream packages to the short form again!

This fragility of the alias syntax was one of the motivations for me to 
put many setGeneric statements of the form setGeneric("someGeneric", 
signature="x") in BiocGenerics over the years. So I don't have many 
dozens of aliases that suddenly break for mysterious reasons ('R CMD 
check' would suddenly starts reporting warnings for these aliases 
despite no changes in my package or in R).

Best,

H.
On 1/29/19 03:16, Martin Maechler wrote: