-----Original Message-----
From: Gabor Grothendieck [mailto:ggrothendieck at gmail.com]
Sent: 22 April 2008 14:12
To: Sklyar, Oleg (MI London)
Cc: Duncan Murdoch; R-devel at r-project.org
Subject: Re: [Rd] graphics::Axis loosing S3/S4 class
attributes of 'x' in 2.7.0 RC
This also affects Axis.yearmon and Axis.yearqtr in the zoo
package which worked in R 2.6.2 and now don't work
properly. It seems more logical to define plot.whatever
to handle the object in question, i.e. we do define plot.zoo,
whereas only the Axis method ought to be required for the X
and Y coordinate axes.
On Tue, Apr 22, 2008 at 8:53 AM, Sklyar, Oleg (MI London)
<osklyar at maninvestments.com> wrote:
Thanks Duncan,
this might explain why Axis.MyClass is never called.
However, it is really not only illogical to define plot.MyClass
instead of Axis.MyClass if the only thing I want is
axis, but it is also broken in R 2.7.0 and here is why.
Let's forget about MyClass and take POSIXct, for which plot.POSIXct
and Axis.POSIXct are defined in graphics. First question
define Axis.POSIXct if it is logical to just define
then, try the following example in 2.7.0 and 2.6.2:
x = Sys.time() + runif(100,1,7200) ## time over two hours, POSIXct
plot(x,1:100)
plot(1:100,x)
The first plot will be correctly formatted in both R versions while
the second one will be *incorrectly* formatted in 2.7.0
xy.coords returns as.double in both, so that might not be
for the problem).
What happens is that plot.POSIXct is called in the former case and
thus we get the correct formatting. However, plot.default
the latter case. In 2.6.2 Axis.POSIXct was the reason why y
correctly formatted here. In 2.7.0 Axis.default is called instead
because class of x is reset.
Now this perfectly indicates why it is logical to have Axis.MyClass
defined (as this two-liner would be called in all possible
producing correct axes independently where it is called
plot.MyClass (which would actually not cover the situation
second argument being MyClass). Surely I can define S4 with
signatures, but logically I would define Axis.MyClass.
Omitting axes completely is not a good options to enforce
default plots, is it?
Dr Oleg Sklyar
Technology Group
Man Investments Ltd
+44 (0)20 7144 3803
osklyar at maninvestments.com
-----Original Message-----
From: Duncan Murdoch [mailto:murdoch at stats.uwo.ca]
Sent: 22 April 2008 13:01
To: Sklyar, Oleg (MI London)
Cc: R-devel at r-project.org
Subject: Re: [Rd] graphics::Axis loosing S3/S4 class
'x' in 2.7.0 RC
On 22/04/2008 7:25 AM, Sklyar, Oleg (MI London) wrote:
Following my previous post on S3 method despatch, I put
in the code of Axis, Axis.default and plot.default in
graphics/R/axis.R and graphics/R/plot.R to print the
at and y on plot. After recompiling R, what I see is
its class attribute (at least for classes not known to
in Axis, called directly from plot.default and this could be
why R did not despatch on Axis.MyClass from my previous
happens for both S3 and S4 classes as in the code below!
even "integer" was reset to numeric in Axis...
If you look at plot.default, you'll see it passes x and y through
xy.coords to get coordinates. That function ends with
return(list(x=as.double(x), y=as.double(y), xlab=xlab, ylab=ylab))
so that's where classes get removed. If you don't want this to
happen, shouldn't you be defining plot.MyClass, or calling the
default with axes=F, and then calling Axis on your object
Is this really an intended behaviour? It looks very wrong to me!
This is documented: ?plot.default tells you to look at
for details of how x and y are handled, and xy.coords
other case, the 'x' argument is coerced to a vector and
returned as *y* component where the resulting 'x'
index vector '1:n'. In this case, the resulting 'xlab'
component
is set to '"Index"'."
Duncan Murdoch
Thanks,
Oleg
*** R version 2.7.0 RC (2008-04-20 r45403)
[/research/osklyar/R-devel]
function (x = NULL, at = NULL, ..., side, labels = NULL) {
cat("In Axis() class(x)=", class(x), ";
"\n", sep = "")
if (!is.null(x))
UseMethod("Axis", x)
else if (!is.null(at))
UseMethod("Axis", at)
else axis(side = side, at = at, labels = labels, ...) }
<environment: namespace:graphics>
function (x = NULL, at = NULL, ..., side, labels = NULL) {
cat("In Axis.default() class(x)=", class(x), "; class(at)=",
class(at), "\n", sep = "")
if (is.null(at) && !is.null(x))
at = pretty(x)
axis(side = side, at = at, labels = labels, ...) }
<environment: namespace:graphics>
setClass("MyClass", representation(smth="character"),
contains="numeric")
[1] "MyClass"
a = new("MyClass", runif(10))
a
An object of class "MyClass"
[1] 0.773237167 0.548630205 0.987956687 0.212667925 0.337135151
0.112210501
[7] 0.007140895 0.972028903 0.443581963 0.536452424
In plot.default() class(x)=integer; class(y)=MyClass In Axis()
class(x)=numeric; class(at)=NULL In Axis.default()
class(at)=NULL In Axis() class(x)=numeric; class(at)=NULL In
Axis.default() class(x)=numeric; class(at)=NULL
In plot.default() class(x)=MyClass; class(y)=integer In Axis()
class(x)=numeric; class(at)=NULL In Axis.default()
class(at)=NULL In Axis() class(x)=numeric; class(at)=NULL In
Axis.default() class(x)=numeric; class(at)=NULL
b = runif(10)
class(b)="AnotherClass"
plot(b,1:10)
In plot.default() class(x)=AnotherClass; class(y)=integer In
Axis() class(x)=numeric; class(at)=NULL In Axis.default()
class(at)=NULL In Axis() class(x)=numeric; class(at)=NULL In
Axis.default() class(x)=numeric; class(at)=NULL
In plot.default() class(x)=integer; class(y)=NULL In Axis()
class(x)=numeric; class(at)=NULL In Axis.default()
class(at)=NULL In Axis() class(x)=numeric; class(at)=NULL In
Axis.default() class(x)=numeric; class(at)=NULL>
R version 2.7.0 RC (2008-04-20 r45403) x86_64-unknown-linux-gnu
locale:
LC_CTYPE=en_GB.UTF-8;LC_NUMERIC=C;LC_TIME=en_GB.UTF-8;LC_COLLATE=C;L
NETARY=C;LC_MESSAGES=en_GB.UTF-8;LC_PAPER=en_GB.UTF-8;LC_NAME=C;LC_A
SS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_GB.UTF-8;LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets
Dr Oleg Sklyar
Technology Group
Man Investments Ltd
+44 (0)20 7144 3803
osklyar at maninvestments.com
********************************************************************
The contents of this email are for the named addressee(s) only.
It contains information which may be confidential and
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
method of communication and Man Investments cannot accept
responsibility for the completeness or accuracy of this
attachments. Whilst Man Investments makes every effort
network free from viruses, it does not accept
computer virus which might be transferred by way of this
attachments. This email does not constitute a request, offer,
recommendation or solicitation of any kind to buy,
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
network to ensure the integrity of its systems, for record
regulatory purposes.
Visit us at: www.maninvestments.com