Skip to content

Overloading %*%

6 messages · Joe Cainey, Ken Knoblauch, Spencer Graves +2 more

#
Joe Cainey <jcainey <at> gmail.com> writes:
clipped
According to the help page for %*%, it is S4 generic but not S3, so
you might make further progress using S4 methods.
best,

Ken
#
Thanks, Ken. 

      1.  How can I find S4 methods for a given function given class(es) 
of objects?  The 'showMethods' function lists available generics for a 
given function;  "showMethods('%*%')" just produced for me a list of 52 
different signatures for "%*%".  However, I don't know how to find the 
functions with methods for a particular class.  The 'methods' function 
will produce either S3 methods for a given function or S3 functions for 
a given class.  It would help me if the 'methods' help page included 
"See Also" and "Examples" for S4 classes also, but it doesn't. 

      2.  How can I find source code for S4 methods?  I tried 
"dumpMethods('%*%', 'mmult.R')" and got an apparently empty file of 0 
KB.  Then I tried 'dumpMethod("%*%", c(x="TsparseMatrix", y="ANY"))' and 
got a file with the following: 

setMethod("%*%", structure(c("TsparseMatrix", "ANY"), .Names = c("x", "y")),
NULL
)

      Thanks again for your reply regarding "%*%". 
      Spencer Graves
knoblauch wrote:
#
Spencer Graves wrote:
Use the 'classes' argument to showMethods, either with or without a 
function as first argument.
use includeDef=TRUE with showMethods, or getMethod to get a specific 
method, or, for some fun, selectMethod to find the method to which 
object dispatch occurs. I'm not sure how to dump the method to a file.

Martin
#
Dear Martin: 

      This is wonderful.  Thank you very much. 

      It would be a great help if your suggestions could be added to 
"See Also" and "Examples" for "methods". 

      Thanks again,
      Spencer Graves
Martin Morgan wrote:
#
SpG> Dear Martin: This is wonderful.  Thank you very much.

    SpG>       It would be a great help if your suggestions
    SpG> could be added to "See Also" and "Examples" for
    SpG> "methods".

?methods has had for years 

  >> Note:
  >> 
  >>      This scheme is called _S3_ (S version 3).  For new projects, it is
  >>      recommended to use the more flexible and robust _S4_ scheme
  >>      provided in the 'methods' package.  Functions can have both S3 and
  >>      S4 methods, and function 'showMethods' will list the S4 methods
  >>      (possibly none).

and so has a link to 'showMethods'.  Since it seems that is overlooked,
I'll add it to 'See also' as well.

Adding an example to 'Examples' is a bit more awkward, 
since it needs to load the methods package;
but I'll add a "don't run" example.

Martin Maechler, ETH Zurich