Re: [Rd] Method dispatch for function

From: Martin Maechler <maechler_at_stat.math.ethz.ch>
Date: Wed, 25 Nov 2009 10:42:02 +0100

>>>>> "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



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 25 Nov 2009 - 09:46:33 GMT

This archive was generated by hypermail 2.2.0 : Wed 25 Nov 2009 - 14:30:47 GMT