[Rd] Method dispatch for function

Martin Maechler maechler at stat.math.ethz.ch
Wed Nov 25 10:42:02 CET 2009


>>>>> "SM" == Stavros Macrakis <macrakis at alum.mit.edu>
>>>>>     on Mon, 23 Nov 2009 11:24:24 -0500 writes:

    SM> (I had sent this to r-help and got no responses -- perhaps r-devel is
    SM> a better list for this question?)

Definitely better, yes.

    SM> How can I determine what S3 method will be called for a particular
    SM> first-argument class?

    SM> I was imagining something like functionDispatch('str','numeric') =>
    SM> utils:::str.default , but I can't find anything like this.

    SM> For that matter, I was wondering if anyone had written a version of
    SM> `methods` which gave their fully qualified names if they were not
    SM> visible, e.g.

    SM> methods('str') =>
    SM>     utils:::str.data.frame    utils:::str.default
    SM> stats:::str.dendrogram    stats:::str.logLik    utils:::str.POSIXt

    SM> or

    SM> methods('str') =>
    SM>      $utils
    SM>            "str.data.frame" "str.default"    "str.POSIXt"
    SM>      $stats
    SM>            "str.dendrogram" "str.logLik"

I'm pretty sure that basically, the current  methods()  function  
"contains" the necessary information internally already
(but beware: methods() is not the simplest of our functions !)

I'd be welcoming back-compatible patches to  methods() {*and*
the corresponding *.Rd  file !} which would provide such
functionality.

I think I would  introduce a third optional argument
(logical or character, specifying the "variants"),
and the result could easily become  back-compatible if the extra information
you want is put as a new column in the "info" attribute (a data
frame) of the current  methods() result.

    SM> Thank you,

You are welcome,
Martin Maechler, ETH Zurich



More information about the R-devel mailing list