From maechler at stat.math.ethz.ch  Wed Nov 25 10:42:02 2009
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Wed, 25 Nov 2009 10:42:02 +0100
Subject: [Rd] Method dispatch for function
In-Reply-To: <8b356f880911230824x4b215dalcaf4f81ce336d17c@mail.gmail.com>
References: <8b356f880911180916w3366bcemd6c2afd5b2a0e4d1@mail.gmail.com>
	<8b356f880911230824x4b215dalcaf4f81ce336d17c@mail.gmail.com>
Message-ID: <19212.64490.91811.259509@lynne.math.ethz.ch>

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



[Rd] Method dispatch for function
Martin Maechler