Skip to content

S3 methods with full name in documentation?

3 messages · Duncan Murdoch, Spencer Graves

#
Hello:


       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.


       Thanks,
       Spencer
#
On 12-03-20 4:40 PM, Spencer Graves wrote:
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.

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.

Duncan Murdoch
#
Hi, Duncan:
On 3/20/2012 6:43 PM, Duncan Murdoch wrote:
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.]
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".


       Thanks, again.


       Best Wishes,
       Spencer