-
Notifications
You must be signed in to change notification settings - Fork 1
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
Dispatch on methods for matrix objects when table objects are supplied #15
Conversation
With this change, |
Hey, great idea. If I understand correctly, the problem is that I see that you chose to use a union class of I am not quite sure how this would work best with the S4 class and dispatch system, so I would trust your judgement Hervé if your say this is not easily possible. However, in that case I wonder if it made sense to rename the class to something more generic (e.g. |
It's only 77 occurrences of Good point about the name of the class. I thought of a name like Also, even though I can't be 100% sure, I'm hoping that with the addition of table we are now covering all the base things that could land in matrixStats arms. In the unlikely event that we are not, I'll add the new member to the class union and rename the class. Replacing the occurrences of |
Back in the old days for BiocNeighbors (I don't remember exactly which package), I did something like: spawnMethods(generic, FUN) {
for (cls in c("matrix", "numeric", "table")) {
setMethod(generic, cls, FUN)
}
}
# to be used like:
spawnMethods("colVars", .matrixStats_colVars)
spawnMethods("rowVars", .matrixStats_rowVars) I think there was some more fiddling required for the |
Right, we have setMethods in S4Vectors that does what spawnMethods does but using something like this in this case would mean generating 72 x 4 methods instead of 72. That sounds like a lot of clutter in the method tables. It would also mean ending up with a lot of clutter in the Usage sections of the 36 man pages because roxygen2 would then report 8 methods per man page instead of 2 only. Note that all the methods in a given man page have exactly the same argument list so this level of repetition is not particularly useful. |
For roxygen, I would imagine that it's actually the opposite problem; it might struggle to link the methods to the documentation if everything is happening inside |
I just tried this and it seems that roxygen2 indeed wouldn't "see" the methods so they don't show up in the Usage section of the man page, only the generic. Also the aliases for the methods don't get added to the Rd file so we end up with a bunch of
Maybe there is a way to "trick" roxygen2 into doing the right thing, I don't know. In any case it doesn't seem that a setMethods/spawnMethods solution would make the content of the man pages particularly easy to control or the package particularly easy to maintain. And we would still bloat the method tables with a myriad of redundant methods. @PeteHaitch are you ok with the current proposal? If so I'll merge this week. |
I'm on leave until Oct 13, so I'm not trying things out for myself but just going on what's posted here in the PR. |
ok, thanks all for the feedback |
Wait! And what about factors? Seems like matrixStats accepts them (even though with some gotcha), Well, turns out that in that case we are lucky:
And this despite the following:
So it works only by chance and because we are in one of those S4 dark corners. No guarantees that this will still work in the future (e.g. when this mess gets fixed in the methods package). Anyways, I don't expect people to call MatrixGenerics functions on their factors in normal situations. Also it's not clear that the matrixStats package intendedly accepts them. |
No description provided.