[Rd] S3 method despatch (changed between 2.6.2 and 2.7.0 RC?)

From: Sklyar, Oleg (MI London) <osklyar_at_maninvestments.com>
Date: Tue, 22 Apr 2008 10:45:28 +0100

Dear developers:

I have observed a change in the behaviour of S3 method despatch (as I guess related to namespaces) between 2.6.2 and yesterday's 2.7.0 RC and would be grateful if you could comment on that:

the 'Axis' function in the 'graphics' namespace calls UseMethod("Axis",x), internally to despatch on the S3 Axis method depending on the type of the argument. Both 2.6.2 and 2.7.0 define the following Axis.* methods in 'graphics': Axis.Date, Axis.POSIXct Axis.POSIXlt and Axis.default. Now, if one defines an Axis.MyClass outside of the 'graphics' namespace, it is called automatically by 2.6.2 on objects of MyClass, i.e. R would search for further method definition outside of the graphics namespace. Looks like this behaviour has changed in 2.7.0 so that UseMethod called in a given namesspace (graphics) does not despatch on methods defined in another namespace (global or another package) as the example below shows.

Have I done something wrong?

Is it an intended behaviour, any idea how to go around it?


PS: The difference in the code below is that 2.6.2 calls Axis.MyClass in plot.default (and thus prints the message), while 2.7.0 does not.

x = 1:5
class(x) = c("MyClass",class(x))
Axis.MyClass = function (x, at, ..., side, labels=TRUE) {

    print("running Axis.MyClass")
    axis(side, at=if(!missing(x)) x else at, labels=labels, ...) }
plot(x, 1:5)

   Non-visible functions are asterisked
> plot(x, 1:5)

[1] "running Axis.MyClass"
> sessionInfo()

R version 2.6.2 (2008-02-08)


attached base packages:
[1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached): [1] rcompgen_0.1-17 tools_2.6.2

   Non-visible functions are asterisked
> plot(x, 1:5)
> sessionInfo()

R version 2.7.0 RC (2008-04-20 r45403)


attached base packages:
[1] stats graphics grDevices utils datasets methods base

loaded via a namespace (and not attached): [1] tools_2.7.0

Dr Oleg Sklyar
Technology Group
Man Investments Ltd
+44 (0)20 7144 3803

The contents of this email are for the named addressee(s) only. It contains information which may be confidential and privileged. If you are not the intended recipient, please notify the sender immediately, destroy this email and any attachments and do not otherwise disclose or use them. Email transmission is not a secure method of communication and Man Investments cannot accept responsibility for the completeness or accuracy of this email or any attachments. Whilst Man Investments makes every effort to keep its network free from viruses, it does not accept responsibility for any computer virus which might be transferred by way of this email or any attachments. This email does not constitute a request, offer, recommendation or solicitation of any kind to buy, subscribe, sell or redeem any investment instruments or to perform other such transactions of any kind. Man Investments reserves the right to monitor, record and retain all electronic communications through its network to ensure the integrity of its systems, for record keeping and regulatory purposes.

Visit us at: www.maninvestments.com

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue 22 Apr 2008 - 09:49:43 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 22 Apr 2008 - 12:31:16 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive