Drew Schmidt
2012-Nov-21 16:19 UTC
[Rd] S3 generic/method consistency issue with R CMD check
Hi, I'm having some trouble setting methods for the qr family of functions. I believe I have distilled my misunderstanding in the code snippet below: foo <- function(x, ...) UseMethod("foo") foo.default <- function(x) { } # foo setGeneric(name = "foo", useAsDefault = foo) setMethod("foo", signature(x="bar"), function(x, ...) { } ) setGeneric(name="foo.Q", function(y, ...) standardGeneric("foo.Q") ) setMethod("foo.Q", signature(y="bar"), function(y, ...) { } ) # QR setGeneric(name = "qr", useAsDefault = qr) setMethod("qr", signature(x="bar"), function(x, ...) { } ) setGeneric(name="qr.Q", function(y, ...) standardGeneric("qr.Q") ) setMethod("qr.Q", signature(y="bar"), function(y, ...) { } ) If you send this to R CMD check, then it gives exactly one WARNING about S3 consistency: * checking S3 generic/method consistency ... WARNING qr: function(x, ...) qr.Q: function(y, ...) This seems to be complaining about the fact that qr.Q dispatches on 'y' instead of 'x'. But there is no complaint about foo/foo.Q even though, I believe, the only difference is a mechanical substitution of generic/method names. Ultimately I would like to be able to set methods for the qr family in a way that maximally mimics R in both syntax and return. I'm clearly doing something wrong, but I'm not really sure how else to proceed. Any help in clearing up my misunderstanding here would be greatly appreciated. Thanks. -- Drew Schmidt National Institute for Computational Sciences University of Tennessee
Drew Schmidt
2012-Nov-28 22:12 UTC
[Rd] S3 generic/method consistency issue with R CMD check
More on this. It looks to me like there is some kind of issue specifically with the qr and qr.* functions in R CMD check, as my last email suggests. Additionally, by changing the dispatch of the qr.* functions from y to x (in this example), such as: setGeneric(name="qr.Q", function(x, ...) standardGeneric("qr.Q"), ) setMethod("qr.Q", signature(x="bar"), function(x, ...) { } ) we avoid the WARNING. So too does: setGeneric(name="qr_Q", function(y, ...) standardGeneric("qr_Q") ) setMethod("qr_Q", signature(y="bar"), function(y, ...) { } ) avoid the WARNING. This suggests to me that R CMD check is incorrectly using "qr"'s dispatch for "qr.Q", even when we specify "qr.Q" as S4 generic with dispatch y. More to the point, it looks to me like R CMD check is applying S3 rules to S4 methods for this specific set of base:: functions. Not sure how else to interpret what I'm seeing here, but I still have doubts as to my understanding of this issue. Would very much appreciate some insight. Apologies in advance if I botch the reply threading; I am using a very limited webmail client and I'm not sure if this will work properly. -- Drew Schmidt National Institute for Computational Sciences University of Tennessee