[Rd] S3 methods with full name in documentation?
spencer.graves at prodsyse.com
Wed Mar 21 08:11:01 CET 2012
On 3/20/2012 6:43 PM, Duncan Murdoch wrote:
> On 12-03-20 4:40 PM, Spencer Graves wrote:
>> Is there a recommended way to inform "R CMD check" that a
>> function like "as.numeric" is NOT a method for the S3 generic function
>> "as" for objects of class "numeric"?
>> I ask, because I'm getting "NOTE" messages for many function
>> names like this (e.g., "density.fd" in the "fda" package): If there
>> were a way to tell "R CMD check" that a function name is NOT a method
>> for an S3 generic, it would make it easier for me to see the messages I
>> should take seriously.
> I don't think so. The problem you are seeing is that "density" is a
> generic, so density.fd looks like a method for it. In fact, if you
> define an object of class "fd" and call density() on it while fda is
> attached, your density.fd function will be called:
> > x <- structure(1, class="fd")
> > density(x)
> Error in inherits(WfdParobj, "fdPar") :
> argument "WfdParobj" is missing, with no default
> So in fact, density.fd *is* an S3 method, even though you didn't know it.
Well, yes, I guess I knew that, but I also knew that "density.fd"
should not be called with the first argument having class "fd", even
more that "as.numeric", which is also recognized as the "numeric" method
for the presumed generic function "as". [Yes, I know that "as" does not
call methods dispatch such as "UseMethod" called by "density", so
"as.numeric" is different from that perspective.]
> Nowadays every package has a namespace, and eventually maybe S3
> methods that aren't declared in the namespace as S3 methods won't be
> recognized as S3 methods. But for now, the only real way around these
> warnings is not to name things in a way that makes them appear to be
> S3 methods.
Thanks. I asked, because I thought there might be something one
could do in a NAMESPACE to avoid this. "density.fd" has been around for
some time, and picking a different name for it (and similar functions in
the fda package) would break too much existing code and impose an
unacceptable burden on long-time fda users to justify that option --
similar to "as.numeric".
> Duncan Murdoch
More information about the R-devel