[Rd] S4: show() method for "MethodDefinition": show non-trivial generic
Martin Maechler
m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Mon Mar 10 16:52:59 CET 2025
Context: We are working to add complex and integer (sparse and dense)
matrix classes to package Matrix.
I'm working with "Ops", notably "Arith" group methods in order
to ensure that all combinations of classes and arithmetic,
comparison, etc operators work.
{ and yes, if you don't know anything about S4 or group methods
(which also exist for S3 or S7) you may now press "delete message"
and go on to something else ...
In the other case, maybe browse ?S4groupGeneric in R or on the web
https://rdrr.io/r/methods/S4groupGeneric.html
}
Debugging problems and testing, for me always involves lots of
showMethods(..) and selectMethod(..) calls such as, say,
selectMethod("+", c("lgCMatrix", "nMatrix"))
For the current (CRAN) version of Matrix, this prints the method
definition, and then ends in
...............
}
<environment: namespace:Matrix>
Signatures:
e1 e2
target "lgCMatrix" "nMatrix"
defined "lMatrix" "nMatrix"
>
I did only ask for the "+" method, but of course,
e.g., when looking where we got this implemented, it is interesting
to note if this is from a "+" or an "Arith" or even (most
generally), an "Ops" method definition.
Now, fortunately, the selectMethod() object *does* contain this
information in its `generic` slot, but the show() method does not show it.
I propose to look into fixing this situation, such that in cases
as this one, there would be one additional line of show() output
` Generic: "Ops" `
and it would show (not the '~~~~~~~~~~~~~~' line I only added
here for visibility) :
...............
}
<environment: namespace:Matrix>
Generic: "Ops"
~~~~~~~~~~~~~~
Signatures:
e1 e2
target "lgCMatrix" "nMatrix"
defined "lMatrix" "nMatrix"
>
Of course this may break people's "pipelines" if they rely on
exact reproduction of R's console (or *.Rout R batch) output.
Apart from that, I see really advantages here, and I don't expect
the net effect to be problematic.
It may affect the many Bioconductor packages using S4, and I'm
particularly glad for feedback from "there".
With thanks in advance,
Martin
--
Martin Maechler
ETH Zurich and R Core team
More information about the R-devel
mailing list