Re: [Rd] prod(0, 1:1000) ; 0 * Inf etc

2008-04-22 Thread Robin Hankin
Interesting problem this.

My take on it would be that the true value depends
on how fast the 0 approaches 0 and how fast the n
approaches infinity.

Consider

f1 - function(n){prod(1/n , seq_len(n))}
f2 - function(n){prod(1/factorial(n) , seq_len(n))}
f3 - function(n){prod(n^(-n) , seq_len(n))}

All these are equal to prod( small number , 1:big number)

but applying these functions to an increasing sequence gives different
behaviour:

  sapply(c(10,100,1000),f1)
[1]  3.628800e+05 9.332622e+155   Inf
  sapply(c(10,100,1000),f2)
[1]   1   1 NaN
  sapply(c(10,100,1000),f3)
[1] 3.628800e-04 9.332622e-43  NaN
 


f1() tends to infinity, f2() tends to 1, and f3() tends to zero.

Figuring out the appropriate limit in cases like this is a job
for a symbolic system.

I would say the original behaviour is desirable.


rksh



On 22 Apr 2008, at 02:43, Bill Dunlap wrote:

 On Mon, 21 Apr 2008, Mathieu Ribatet wrote:

 I definitely do agree with you.
 Basically, I see two different ways to proceed:

   1. one could first check if there are any 0 in the vector and then
  return 0 without computing the product

 That would fail for prod(0,Inf), which should return the same
 thing as 0*Inf=NaN.  Similarly for prod(0,NA) and prod(0,NaN).
 Scanning for all these things might well be slower than just
 doing the multiplications.  Scanning also means that 0 is treated
 more commutatively than other numbers.

   2. or convert prod(x1, x2, x3) in prod(c(x1, x2, x3))

 c() can convert values of classy objects in undesirable ways.
 E.g.,
 now-Sys.time()
 min(now-file.info(.)$mtime, now-file.info(..)$mtime)
   Time difference of 3787.759 secs
 min(c(now-file.info(.)$mtime, now-file.info(..)$mtime))
   [1] 1.052155

 This may be considered a bug in c(), at least for class
 timediff (and  factor and ordered), but c() removes
 attributes.

 Martin Maechler a écrit :
 I think most of us would expect  prod(0:1000)  to return 0, and ...


 ... it does.

 However, many of us also expect
  prod(x1, x2)to be equivalent to
  prod(c(x1,x2))
 the same as we can expect that for min(), max(), sum() and such
 members of the Summary group.

 Consequently, prod(0, 1:1000) should also return 0,
 but as you see, it gives  NaN  which may be a bit puzzling...
 The explanation is relatively simple:

 1) The internal implementation uses

 prod(x1, x2) := prod(x1) * prod(x2)

   which in this case is

 2)  0 * Infand that is not 0, but NaN;

  not necessarily because we would want that, but I think just
  because the underlying C math library does so.


 I would personally like to change both behaviors,
 but am currently only proposing to change  prod() such as to
 return 0 in such cases.
 This would be S-plus compatible, in case that matters.

 Opinions?

 Martin Maechler, ETH Zurich  R-core

 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel


 --
 Institute of Mathematics
 Ecole Polytechnique Fédérale de Lausanne
 STAT-IMA-FSB-EPFL, Station 8
 CH-1015 Lausanne   Switzerland
 http://stat.epfl.ch/
 Tel: + 41 (0)21 693 7907

 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel


 
 Bill Dunlap
 Insightful Corporation
 bill at insightful dot com
 360-428-8146

 All statements in this message represent the opinions of the author  
 and do
 not necessarily reflect Insightful Corporation policy or position.

 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel

--
Robin Hankin
Uncertainty Analyst and Neutral Theorist,
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
  tel  023-8059-7743

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] prod(0, 1:1000) ; 0 * Inf etc

2008-04-22 Thread Mathieu Ribatet

 I definitely do agree with you.
 Basically, I see two different ways to proceed:

1. one could first check if there are any 0 in the vector and then
   return 0 without computing the product
 

 That would fail for prod(0,Inf), which should return the same
 thing as 0*Inf=NaN.  Similarly for prod(0,NA) and prod(0,NaN).
 Scanning for all these things might well be slower than just
 doing the multiplications.  Scanning also means that 0 is treated
 more commutatively than other numbers.

   
Yes you're right when vectors have special values - oupppsss. However, 
for the more commutatively behaviour of 0, to me this is not a problem 
- just a computational trick. We all know easily how to multiply by 11. 
This is just the same. What we want is that the operator is still 
commutative which (of course) is still the case.

However, you're probably right with the time consuming approach of 
checking 0 (as well as special values) within the vector. The question 
is what is the main objective? Fast computations but could lead to 
miss-calculations - in rarely cases. Or run codes a little bit slower 
while returning the appropriate values - a little bit more often.

I'm not sure users do so many times products of really huge length 
vectors though - but this is only my point of view.
Best,
Mathieu
2. or convert prod(x1, x2, x3) in prod(c(x1, x2, x3))
 

 c() can convert values of classy objects in undesirable ways.
 E.g.,
 now-Sys.time()
 min(now-file.info(.)$mtime, now-file.info(..)$mtime)
Time difference of 3787.759 secs
 min(c(now-file.info(.)$mtime, now-file.info(..)$mtime))
[1] 1.052155

 This may be considered a bug in c(), at least for class
 timediff (and  factor and ordered), but c() removes
 attributes.

   
 Martin Maechler a ?crit :
 
 I think most of us would expect  prod(0:1000)  to return 0, and ...


 ... it does.

 However, many of us also expect
   prod(x1, x2)to be equivalent to
   prod(c(x1,x2))
 the same as we can expect that for min(), max(), sum() and such
 members of the Summary group.

 Consequently, prod(0, 1:1000) should also return 0,
 but as you see, it gives  NaN  which may be a bit puzzling...
 The explanation is relatively simple:

 1) The internal implementation uses

  prod(x1, x2) := prod(x1) * prod(x2)

which in this case is

 2)  0 * Infand that is not 0, but NaN;

   not necessarily because we would want that, but I think just
   because the underlying C math library does so.


 I would personally like to change both behaviors,
 but am currently only proposing to change  prod() such as to
 return 0 in such cases.
 This would be S-plus compatible, in case that matters.

 Opinions?

 Martin Maechler, ETH Zurich  R-core

 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel

   
 --
 Institute of Mathematics
 Ecole Polytechnique F?d?rale de Lausanne
 STAT-IMA-FSB-EPFL, Station 8
 CH-1015 Lausanne   Switzerland
 http://stat.epfl.ch/
 Tel: + 41 (0)21 693 7907

 __
 R-devel@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-devel

 

 
 Bill Dunlap
 Insightful Corporation
 bill at insightful dot com
 360-428-8146

  All statements in this message represent the opinions of the author and do
  not necessarily reflect Insightful Corporation policy or position.
   

-- 
Institute of Mathematics
Ecole Polytechnique Fédérale de Lausanne
STAT-IMA-FSB-EPFL, Station 8
CH-1015 Lausanne   Switzerland
http://stat.epfl.ch/
Tel: + 41 (0)21 693 7907

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


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

2008-04-22 Thread Sklyar, Oleg (MI London)
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?

Thanks,
Oleg

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, ...)
}
methods(Axis)
plot(x, 1:5)

==  Output from 2.6.2 RC (2008-02-08)
===
 methods(Axis)
[1] Axis.Date*Axis.MyClass  Axis.POSIXct* Axis.POSIXlt*
Axis.default*

   Non-visible functions are asterisked
 plot(x, 1:5)
[1] running Axis.MyClass

 sessionInfo()
R version 2.6.2 (2008-02-08)
x86_64-unknown-linux-gnu

locale:
LC_CTYPE=en_GB.UTF-8;LC_NUMERIC=C;LC_TIME=en_GB.UTF-8;LC_COLLATE=C;LC_MO
NETARY=en_GB.UTF-8;LC_MESSAGES=en_GB.UTF-8;LC_PAPER=en_GB.UTF-8;LC_NAME=
C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_GB.UTF-8;LC_IDENTIFICATI
ON=C

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

==  Output from 2.7.0 RC (2008-04-20 r45403)

 methods(Axis)
[1] Axis.Date*Axis.MyClass  Axis.POSIXct* Axis.POSIXlt*
Axis.default*

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

 sessionInfo()
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;LC_MO
NETARY=C;LC_MESSAGES=en_GB.UTF-8;LC_PAPER=en_GB.UTF-8;LC_NAME=C;LC_ADDRE
SS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_GB.UTF-8;LC_IDENTIFICATION=C

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
[EMAIL PROTECTED]


**
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@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Seqfault, Address 0, track X11() (PR#11231)

2008-04-22 Thread liqun . xing
Full_Name: Liqun Xing
Version: 2.6.2
OS: Solaris 9
Submission from: (NULL) (76.182.91.82)


When first time launch X11(), it was fine. However, when closed the X11 windon
by clicking the close button, or closed it off by command Dev.off() and launched
the X11() again, got segfault, and asking for exiting R and other options.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] graphics::Axis loosing S3/S4 class attributes of 'x' in 2.7.0 RC

2008-04-22 Thread Sklyar, Oleg (MI London)
Following my previous post on S3 method despatch, I put debug messages
in the code of Axis, Axis.default and plot.default in graphics/R/axis.R
and graphics/R/plot.R to print the class of x, at and y on plot. After
recompiling R, what I see is that x *lost* its class attribute (at least
for classes not known to 'graphics') in Axis, called directly from
plot.default and this could be the reason why R did not despatch on
Axis.MyClass from my previous post. This happens for both S3 and S4
classes as in the code below! Funny enough, even integer was reset to
numeric in Axis...

Is this really an intended behaviour? It looks very wrong to me!

Thanks,
Oleg

*** R version 2.7.0 RC (2008-04-20 r45403) [/research/osklyar/R-devel]
***
 Axis
function (x = NULL, at = NULL, ..., side, labels = NULL)
{
cat(In Axis() class(x)=, class(x), ; class(at)=, class(at),
\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
 graphics:::Axis.default
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
Slot smth:
character(0)
 plot(1:10,a)
In plot.default() class(x)=integer; class(y)=MyClass
In Axis() class(x)=numeric; class(at)=NULL
In Axis.default() class(x)=numeric; class(at)=NULL
In Axis() class(x)=numeric; class(at)=NULL
In Axis.default() class(x)=numeric; class(at)=NULL
 plot(a,1:10)
In plot.default() class(x)=MyClass; class(y)=integer
In Axis() class(x)=numeric; class(at)=NULL
In Axis.default() class(x)=numeric; 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(x)=numeric; class(at)=NULL
In Axis() class(x)=numeric; class(at)=NULL
In Axis.default() class(x)=numeric; class(at)=NULL
 plot(1:10)
In plot.default() class(x)=integer; class(y)=NULL
In Axis() class(x)=numeric; class(at)=NULL
In Axis.default() class(x)=numeric; class(at)=NULL
In Axis() class(x)=numeric; class(at)=NULL
In Axis.default() class(x)=numeric; class(at)=NULL
 sessionInfo()
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;LC_MO
NETARY=C;LC_MESSAGES=en_GB.UTF-8;LC_PAPER=en_GB.UTF-8;LC_NAME=C;LC_ADDRE
SS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_GB.UTF-8;LC_IDENTIFICATION=C

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


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


**
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@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] graphics::Axis loosing S3/S4 class attributes of 'x' in 2.7.0 RC

2008-04-22 Thread Duncan Murdoch
On 22/04/2008 7:25 AM, Sklyar, Oleg (MI London) wrote:
 Following my previous post on S3 method despatch, I put debug messages
 in the code of Axis, Axis.default and plot.default in graphics/R/axis.R
 and graphics/R/plot.R to print the class of x, at and y on plot. After
 recompiling R, what I see is that x *lost* its class attribute (at least
 for classes not known to 'graphics') in Axis, called directly from
 plot.default and this could be the reason why R did not despatch on
 Axis.MyClass from my previous post. This happens for both S3 and S4
 classes as in the code below! Funny enough, 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 yourself?

 Is this really an intended behaviour? It looks very wrong to me!

This is documented:  ?plot.default tells you to look at ?xy.coords for 
details of how x and y are handled, and xy.coords
says In any other case, the 'x' argument is coerced to a vector and
  returned as *y* component where the resulting 'x' is just the
  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]
 ***
 Axis
 function (x = NULL, at = NULL, ..., side, labels = NULL)
 {
 cat(In Axis() class(x)=, class(x), ; class(at)=, class(at),
 \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
 graphics:::Axis.default
 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
 Slot smth:
 character(0)
 plot(1:10,a)
 In plot.default() class(x)=integer; class(y)=MyClass
 In Axis() class(x)=numeric; class(at)=NULL
 In Axis.default() class(x)=numeric; class(at)=NULL
 In Axis() class(x)=numeric; class(at)=NULL
 In Axis.default() class(x)=numeric; class(at)=NULL
 plot(a,1:10)
 In plot.default() class(x)=MyClass; class(y)=integer
 In Axis() class(x)=numeric; class(at)=NULL
 In Axis.default() class(x)=numeric; 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(x)=numeric; class(at)=NULL
 In Axis() class(x)=numeric; class(at)=NULL
 In Axis.default() class(x)=numeric; class(at)=NULL
 plot(1:10)
 In plot.default() class(x)=integer; class(y)=NULL
 In Axis() class(x)=numeric; class(at)=NULL
 In Axis.default() class(x)=numeric; class(at)=NULL
 In Axis() class(x)=numeric; class(at)=NULL
 In Axis.default() class(x)=numeric; class(at)=NULL
 sessionInfo()
 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;LC_MO
 NETARY=C;LC_MESSAGES=en_GB.UTF-8;LC_PAPER=en_GB.UTF-8;LC_NAME=C;LC_ADDRE
 SS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_GB.UTF-8;LC_IDENTIFICATION=C
 
 attached base packages:
 [1] stats graphics  grDevices utils datasets  methods   base
 
 
 Dr Oleg Sklyar
 Technology Group
 Man Investments Ltd
 +44 (0)20 7144 3803
 [EMAIL PROTECTED]
 
 
 **
 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, 

Re: [Rd] graphics::Axis loosing S3/S4 class attributes of 'x' in 2.7.0 RC

2008-04-22 Thread Sklyar, Oleg (MI London)
Duncan,

looking further, what has changed from 2.6.2 into 2.7.0 are the
following two lines in plot.default, which I think were logical before
and are not really logical now:

plot.R: plot.default (2.6.2):
if (axes) {
localAxis(x, side=1, ...)
localAxis(y, side=2, ...)
}

plot.R: plot.default (2.7.0):
...
if (axes) {
localAxis(xy$x, side=1, ...)
localAxis(xy$y, side=2, ...)
}

The fact that xy.coords is called does not really matter.


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

 -Original Message-
 From: Duncan Murdoch [mailto:[EMAIL PROTECTED] 
 Sent: 22 April 2008 13:01
 To: Sklyar, Oleg (MI London)
 Cc: R-devel@r-project.org
 Subject: Re: [Rd] graphics::Axis loosing S3/S4 class 
 attributes of '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 
 debug messages 
  in the code of Axis, Axis.default and plot.default in 
  graphics/R/axis.R and graphics/R/plot.R to print the class of x, at 
  and y on plot. After recompiling R, what I see is that x *lost* its 
  class attribute (at least for classes not known to 'graphics') in 
  Axis, called directly from plot.default and this could be 
 the reason 
  why R did not despatch on Axis.MyClass from my previous post. This 
  happens for both S3 and S4 classes as in the code below! 
 Funny enough, 
  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 
 yourself?
 
  Is this really an intended behaviour? It looks very wrong to me!
 
 This is documented:  ?plot.default tells you to look at 
 ?xy.coords for details of how x and y are handled, and 
 xy.coords says In any other case, the 'x' argument is 
 coerced to a vector and
   returned as *y* component where the resulting 'x' is just the
   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]
  ***
  Axis
  function (x = NULL, at = NULL, ..., side, labels = NULL) {
  cat(In Axis() class(x)=, class(x), ; class(at)=, class(at),
  \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
  graphics:::Axis.default
  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 Slot smth:
  character(0)
  plot(1:10,a)
  In plot.default() class(x)=integer; class(y)=MyClass In Axis() 
  class(x)=numeric; class(at)=NULL In Axis.default() 
 class(x)=numeric; 
  class(at)=NULL In Axis() class(x)=numeric; class(at)=NULL In 
  Axis.default() class(x)=numeric; class(at)=NULL
  plot(a,1:10)
  In plot.default() class(x)=MyClass; class(y)=integer In Axis() 
  class(x)=numeric; class(at)=NULL In Axis.default() 
 class(x)=numeric; 
  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(x)=numeric; 
  class(at)=NULL In Axis() class(x)=numeric; class(at)=NULL In 
  Axis.default() class(x)=numeric; class(at)=NULL
  plot(1:10)
  In plot.default() class(x)=integer; class(y)=NULL In Axis() 
  class(x)=numeric; class(at)=NULL In Axis.default() 
 class(x)=numeric; 
  class(at)=NULL In Axis() class(x)=numeric; class(at)=NULL In 
  Axis.default() class(x)=numeric; class(at)=NULL
  sessionInfo()
  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;LC_
  MO 
  
 NETARY=C;LC_MESSAGES=en_GB.UTF-8;LC_PAPER=en_GB.UTF-8;LC_NAME=C;LC_ADD
  RE 
 SS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_GB.UTF-8;LC_IDENTIFICATION=C
  
  attached base packages:
  [1] stats graphics  grDevices utils datasets  methods   base
  
  
  

Re: [Rd] graphics::Axis loosing S3/S4 class attributes of 'x' in 2.7.0 RC

2008-04-22 Thread Gabor Grothendieck
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)
[EMAIL PROTECTED] 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 formatting of the 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 would be, why
 define Axis.POSIXct if it is logical to just define plot.POSIXct. But
 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 (funny enough
 xy.coords returns as.double in both, so that might not be the reason 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 is called in the
 latter case. In 2.6.2 Axis.POSIXct was the reason why y axis was
 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 situations
 producing correct axes independently where it is called from) and not
 plot.MyClass (which would actually not cover the situation of only the
 second argument being MyClass). Surely I can define S4 with multiple
 signatures, but logically I would define Axis.MyClass.

 Omitting axes completely is not a good options to enforce on users for
 default plots, is it?


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


  -Original Message-
  From: Duncan Murdoch [mailto:[EMAIL PROTECTED]
  Sent: 22 April 2008 13:01
  To: Sklyar, Oleg (MI London)
  Cc: R-devel@r-project.org
  Subject: Re: [Rd] graphics::Axis loosing S3/S4 class
  attributes of '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
  debug messages
   in the code of Axis, Axis.default and plot.default in
   graphics/R/axis.R and graphics/R/plot.R to print the class of x, at
   and y on plot. After recompiling R, what I see is that x *lost* its
   class attribute (at least for classes not known to 'graphics') in
   Axis, called directly from plot.default and this could be
  the reason
   why R did not despatch on Axis.MyClass from my previous post. This
   happens for both S3 and S4 classes as in the code below!
  Funny enough,
   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
  yourself?
 
   Is this really an intended behaviour? It looks very wrong to me!
 
  This is documented:  ?plot.default tells you to look at
  ?xy.coords for details of how x and y are handled, and
  xy.coords says In any other case, the 'x' argument is
  coerced to a vector and
returned as *y* component where the resulting 'x' is just the
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]
   ***
   Axis
   function (x = NULL, at = NULL, ..., side, labels = NULL) {
   cat(In Axis() class(x)=, class(x), ; class(at)=, class(at),
   \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
   graphics:::Axis.default
   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 

Re: [Rd] graphics::Axis loosing S3/S4 class attributes of 'x' in 2.7.0 RC

2008-04-22 Thread Sklyar, Oleg (MI London)
Lines 69/70 in plot.R of graphics:

xy$x and xy$y should have stayed as x and y

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

 -Original Message-
 From: Gabor Grothendieck [mailto:[EMAIL PROTECTED] 
 Sent: 22 April 2008 14:12
 To: Sklyar, Oleg (MI London)
 Cc: Duncan Murdoch; R-devel@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) 
 [EMAIL PROTECTED] 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 
 formatting of the 
  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 
 would be, why 
  define Axis.POSIXct if it is logical to just define 
 plot.POSIXct. But 
  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 
 (funny enough 
  xy.coords returns as.double in both, so that might not be 
 the reason 
  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 
 is called in 
  the latter case. In 2.6.2 Axis.POSIXct was the reason why y 
 axis was 
  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 
 situations 
  producing correct axes independently where it is called 
 from) and not 
  plot.MyClass (which would actually not cover the situation 
 of only the 
  second argument being MyClass). Surely I can define S4 with 
 multiple 
  signatures, but logically I would define Axis.MyClass.
 
  Omitting axes completely is not a good options to enforce 
 on users for 
  default plots, is it?
 
 
  Dr Oleg Sklyar
  Technology Group
  Man Investments Ltd
  +44 (0)20 7144 3803
  [EMAIL PROTECTED]
 
 
   -Original Message-
   From: Duncan Murdoch [mailto:[EMAIL PROTECTED]
   Sent: 22 April 2008 13:01
   To: Sklyar, Oleg (MI London)
   Cc: R-devel@r-project.org
   Subject: Re: [Rd] graphics::Axis loosing S3/S4 class 
 attributes of 
   '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
   debug messages
in the code of Axis, Axis.default and plot.default in 
graphics/R/axis.R and graphics/R/plot.R to print the 
 class of x, 
at and y on plot. After recompiling R, what I see is 
 that x *lost* 
its class attribute (at least for classes not known to 
 'graphics') 
in Axis, called directly from plot.default and this could be
   the reason
why R did not despatch on Axis.MyClass from my previous 
 post. This 
happens for both S3 and S4 classes as in the code below!
   Funny enough,
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 
 yourself?
  
Is this really an intended behaviour? It looks very wrong to me!
  
   This is documented:  ?plot.default tells you to look at 
 ?xy.coords 
   for details of how x and y are handled, and xy.coords 
 says In any 
   other case, the 'x' argument is coerced to a vector and
 returned as *y* component where the resulting 'x' 
 is just the
 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]
***
Axis
function (x = NULL, at = NULL, ..., side, labels = NULL) {
cat(In Axis() class(x)=, class(x), ; 
 class(at)=, class(at),
\n, sep = )
if (!is.null(x))
UseMethod(Axis, x)
else if (!is.null(at))
UseMethod(Axis, at)
else axis(side = side, 

Re: [Rd] graphics::Axis loosing S3/S4 class attributes of 'x' in 2.7.0 RC

2008-04-22 Thread Duncan Murdoch
On 4/22/2008 9:08 AM, Sklyar, Oleg (MI London) wrote:
 Duncan,
 
 looking further, what has changed from 2.6.2 into 2.7.0 are the
 following two lines in plot.default, which I think were logical before
 and are not really logical now:

I believe it is behaving as documented now, so the behaviour is 
logical, even if it may not be convenient.  In your example

x = Sys.time() + runif(100,1,7200) ## time over two hours, POSIXct
plot(x, 1:100)
plot(1:100, x)

the 1st works in 2.6.2 and 2.7.0 and the second only works in 2.6.2. 
But the change below was designed to fix the case

plot(x)

which works in 2.7.0 and *not* in 2.6.2, so reverting the change is not 
the way to address this.

Duncan Murdoch

 
 plot.R: plot.default (2.6.2):
 if (axes) {
   localAxis(x, side=1, ...)
   localAxis(y, side=2, ...)
 }
 
 plot.R: plot.default (2.7.0):
 ...
 if (axes) {
   localAxis(xy$x, side=1, ...)
   localAxis(xy$y, side=2, ...)
 }
 
 The fact that xy.coords is called does not really matter.
 
 
 Dr Oleg Sklyar
 Technology Group
 Man Investments Ltd
 +44 (0)20 7144 3803
 [EMAIL PROTECTED] 
 
 -Original Message-
 From: Duncan Murdoch [mailto:[EMAIL PROTECTED] 
 Sent: 22 April 2008 13:01
 To: Sklyar, Oleg (MI London)
 Cc: R-devel@r-project.org
 Subject: Re: [Rd] graphics::Axis loosing S3/S4 class 
 attributes of '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 
 debug messages 
  in the code of Axis, Axis.default and plot.default in 
  graphics/R/axis.R and graphics/R/plot.R to print the class of x, at 
  and y on plot. After recompiling R, what I see is that x *lost* its 
  class attribute (at least for classes not known to 'graphics') in 
  Axis, called directly from plot.default and this could be 
 the reason 
  why R did not despatch on Axis.MyClass from my previous post. This 
  happens for both S3 and S4 classes as in the code below! 
 Funny enough, 
  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 
 yourself?
 
  Is this really an intended behaviour? It looks very wrong to me!
 
 This is documented:  ?plot.default tells you to look at 
 ?xy.coords for details of how x and y are handled, and 
 xy.coords says In any other case, the 'x' argument is 
 coerced to a vector and
   returned as *y* component where the resulting 'x' is just the
   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]
  ***
  Axis
  function (x = NULL, at = NULL, ..., side, labels = NULL) {
  cat(In Axis() class(x)=, class(x), ; class(at)=, class(at),
  \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
  graphics:::Axis.default
  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 Slot smth:
  character(0)
  plot(1:10,a)
  In plot.default() class(x)=integer; class(y)=MyClass In Axis() 
  class(x)=numeric; class(at)=NULL In Axis.default() 
 class(x)=numeric; 
  class(at)=NULL In Axis() class(x)=numeric; class(at)=NULL In 
  Axis.default() class(x)=numeric; class(at)=NULL
  plot(a,1:10)
  In plot.default() class(x)=MyClass; class(y)=integer In Axis() 
  class(x)=numeric; class(at)=NULL In Axis.default() 
 class(x)=numeric; 
  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(x)=numeric; 
  class(at)=NULL In Axis() class(x)=numeric; class(at)=NULL In 
  Axis.default() class(x)=numeric; class(at)=NULL
  plot(1:10)
  In plot.default() class(x)=integer; class(y)=NULL In Axis() 
  class(x)=numeric; class(at)=NULL In Axis.default() 
 class(x)=numeric; 
  

Re: [Rd] graphics::Axis loosing S3/S4 class attributes of 'x' in 2.7.0 RC

2008-04-22 Thread Sklyar, Oleg (MI London)
So if plot(x) produced rubbish in 2.6.2 in sense of axis formatting
would not that mean that either plot.POSIXct or in fact Axis.POSIXct is
incorrectly defined? I will have a look at those to see if I can find a
fix.

Anyway, it does not seem to have any sense to argue any further, because
for me documented and logical are not the same things. 

This fix effectively makes Axis.POSIXct and all other Axis.* methods
useless as there is now no despatch on Axis taking place in plot.default
and thus it is not clear why Axis and not Axis.default is actually used?
This would at least make the code cleaner. I was thinking that the idea
of methods is actually to have different implementations depending on
the argument class rather than coerce everything to double and use the
default instead.

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

 -Original Message-
 From: Duncan Murdoch [mailto:[EMAIL PROTECTED] 
 Sent: 22 April 2008 14:24
 To: Sklyar, Oleg (MI London)
 Cc: R-devel@r-project.org
 Subject: Re: [Rd] graphics::Axis loosing S3/S4 class 
 attributes of 'x' in 2.7.0 RC
 
 On 4/22/2008 9:08 AM, Sklyar, Oleg (MI London) wrote:
  Duncan,
  
  looking further, what has changed from 2.6.2 into 2.7.0 are the 
  following two lines in plot.default, which I think were 
 logical before 
  and are not really logical now:
 
 I believe it is behaving as documented now, so the behaviour 
 is logical, even if it may not be convenient.  In your example
 
 x = Sys.time() + runif(100,1,7200) ## time over two hours, 
 POSIXct plot(x, 1:100) plot(1:100, x)
 
 the 1st works in 2.6.2 and 2.7.0 and the second only works in 2.6.2. 
 But the change below was designed to fix the case
 
 plot(x)
 
 which works in 2.7.0 and *not* in 2.6.2, so reverting the 
 change is not the way to address this.
 
 Duncan Murdoch
 
  
  plot.R: plot.default (2.6.2):
  if (axes) {
  localAxis(x, side=1, ...)
  localAxis(y, side=2, ...)
  }
  
  plot.R: plot.default (2.7.0):
  ...
  if (axes) {
  localAxis(xy$x, side=1, ...)
  localAxis(xy$y, side=2, ...)
  }
  
  The fact that xy.coords is called does not really matter.
  
  
  Dr Oleg Sklyar
  Technology Group
  Man Investments Ltd
  +44 (0)20 7144 3803
  [EMAIL PROTECTED]
  
  -Original Message-
  From: Duncan Murdoch [mailto:[EMAIL PROTECTED]
  Sent: 22 April 2008 13:01
  To: Sklyar, Oleg (MI London)
  Cc: R-devel@r-project.org
  Subject: Re: [Rd] graphics::Axis loosing S3/S4 class attributes of 
  '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
  debug messages
   in the code of Axis, Axis.default and plot.default in 
   graphics/R/axis.R and graphics/R/plot.R to print the 
 class of x, at 
   and y on plot. After recompiling R, what I see is that x 
 *lost* its 
   class attribute (at least for classes not known to 
 'graphics') in 
   Axis, called directly from plot.default and this could be
  the reason
   why R did not despatch on Axis.MyClass from my previous 
 post. This 
   happens for both S3 and S4 classes as in the code below!
  Funny enough,
   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 yourself?
  
   Is this really an intended behaviour? It looks very wrong to me!
  
  This is documented:  ?plot.default tells you to look at ?xy.coords 
  for details of how x and y are handled, and xy.coords says In any 
  other case, the 'x' argument is coerced to a vector and
returned as *y* component where the resulting 'x' is just the
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]
   ***
   Axis
   function (x = NULL, at = NULL, ..., side, labels = NULL) {
   cat(In Axis() class(x)=, class(x), ; class(at)=, 
 class(at),
   \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
   graphics:::Axis.default
   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)
  

Re: [Rd] graphics::Axis loosing S3/S4 class attributes of 'x' in 2.7.0 RC

2008-04-22 Thread Gabor Grothendieck
On Tue, Apr 22, 2008 at 9:24 AM, Duncan Murdoch [EMAIL PROTECTED] wrote:
 On 4/22/2008 9:08 AM, Sklyar, Oleg (MI London) wrote:
  Duncan,
 
  looking further, what has changed from 2.6.2 into 2.7.0 are the
  following two lines in plot.default, which I think were logical before
  and are not really logical now:

 I believe it is behaving as documented now, so the behaviour is
 logical, even if it may not be convenient.  In your example

 x = Sys.time() + runif(100,1,7200) ## time over two hours, POSIXct
 plot(x, 1:100)
 plot(1:100, x)

 the 1st works in 2.6.2 and 2.7.0 and the second only works in 2.6.2.
 But the change below was designed to fix the case

 plot(x)


In what sense is plot(x) fixed?  When I try it I get numbers on both axes --
times on neither.   Clearly Axis should not behave in a way which effectively
makes it useless and breaks reasonable old code.

 R.version.string
[1] R version 2.7.0 RC (2008-04-17 r45367)

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] graphics::Axis loosing S3/S4 class attributes of 'x' in 2.7.0 RC

2008-04-22 Thread Martin Maechler
 OlegS == Sklyar, Oleg \(MI London\) [EMAIL PROTECTED]
 on Tue, 22 Apr 2008 14:44:01 +0100 writes:

OlegS So if plot(x) produced rubbish in 2.6.2 in sense of axis formatting
OlegS would not that mean that either plot.POSIXct or in fact Axis.POSIXct 
is
OlegS incorrectly defined? I will have a look at those to see if I can 
find a
OlegS fix.

Me too.


OlegS Anyway, it does not seem to have any sense to argue any further, 
because
OlegS for me documented and logical are not the same things. 

It still makes much sense to discuss further.

I agree with you that the change 2.6.2 - 2.7.0  fixed one problem
but introduced another one.

2.7.1 (and before that 2.7.0 patched) should hopefully be
better than both 2.6.2 and 2.7.0

My current version is

if (axes) {
localAxis(if(is.null(y)) xy$x else x, side = 1, ...)
localAxis(if(is.null(y))  x   else y, side = 2, ...)
}

which is I think better already than either predecessor;
it definitely is compatible with Rversion = 2.6.2 when both
(x,y) are specified,
and it produces the correct axes in these three cases:

## Axis() calls via plot()
x - as.Date(2008-04-22 09:45) + (i - 0:4)
plot(x)# not ok in 2.6.2, nor 2.7.0
plot(x, i)# ok in 2.6.2  and 2.7.0
plot(i, x)# ok in 2.6.2 and not in 2.7.0


I'm grateful for further examples, preferably not using code
from packages outside of standard R.

Martin Maechler, ETH Zurich


OlegS This fix effectively makes Axis.POSIXct and all other Axis.* 
methods
OlegS useless as there is now no despatch on Axis taking place in 
plot.default
OlegS and thus it is not clear why Axis and not Axis.default is actually 
used?
OlegS This would at least make the code cleaner. I was thinking that the 
idea
OlegS of methods is actually to have different implementations depending on
OlegS the argument class rather than coerce everything to double and use 
the
OlegS default instead.

OlegS Dr Oleg Sklyar
OlegS Technology Group
OlegS Man Investments Ltd
OlegS +44 (0)20 7144 3803
OlegS [EMAIL PROTECTED] 

 -Original Message-
 From: Duncan Murdoch [mailto:[EMAIL PROTECTED] 
 Sent: 22 April 2008 14:24
 To: Sklyar, Oleg (MI London)
 Cc: R-devel@r-project.org
 Subject: Re: [Rd] graphics::Axis loosing S3/S4 class 
 attributes of 'x' in 2.7.0 RC
 
 On 4/22/2008 9:08 AM, Sklyar, Oleg (MI London) wrote:
  Duncan,
  
  looking further, what has changed from 2.6.2 into 2.7.0 are the 
  following two lines in plot.default, which I think were 
 logical before 
  and are not really logical now:
 
 I believe it is behaving as documented now, so the behaviour 
 is logical, even if it may not be convenient.  In your example
 
 x = Sys.time() + runif(100,1,7200) ## time over two hours, 
 POSIXct plot(x, 1:100) plot(1:100, x)
 
 the 1st works in 2.6.2 and 2.7.0 and the second only works in 2.6.2. 
 But the change below was designed to fix the case
 
 plot(x)
 
 which works in 2.7.0 and *not* in 2.6.2, so reverting the 
 change is not the way to address this.
 
 Duncan Murdoch
 
  
  plot.R: plot.default (2.6.2):
  if (axes) {
 localAxis(x, side=1, ...)
 localAxis(y, side=2, ...)
  }
  
  plot.R: plot.default (2.7.0):
  ...
  if (axes) {
 localAxis(xy$x, side=1, ...)
 localAxis(xy$y, side=2, ...)
  }
  
  The fact that xy.coords is called does not really matter.
  
  
[..]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] graphics::Axis loosing S3/S4 class attributes of 'x' in 2.7.0 RC

2008-04-22 Thread Sklyar, Oleg (MI London)
Ok, so what's wrong with the following fix for plot(x) that would
actually fix what needs to be fixed instead of changing plot.default?
Fix means reverting plot.default in 2.7.0 to what it was (if testing in
2.7.0, copy and paste the OLD plot.default into the .GlobalEnv):

plot.POSIXct - function(x, y, xlab = , ...) {
if (!missing(y)) {
side = 1
plotDef - function(x, y, xaxt, xlab, ...) plot.default(x, y,
xaxt=n, xlab=xlab, ...)
plotDef(x, y, xlab=xlab, ...)
} else {
side = 2
plotDef - function(x, y, yaxt, xlab, ...) plot.default(x, y,
yaxt=n, xlab=xlab, ...)
plotDef(seq_along(x), x, xlab=xlab, ...)
}
## trick to remove arguments intended for title() or plot.default()
axisInt - function(x, type, main, sub, xlab, ylab, col, lty, lwd,
xlim, ylim, bg, pch, log, asp, axes, frame.plot,
...)
axis.POSIXct(side, x, ...)
dots - list(...)
axes - if(axes %in% names(dots)) dots$axes else TRUE
xaxt - if(xaxt %in% names(dots)) dots$xaxt else par(xaxt)
if(axes  xaxt != n) axisInt(x, ...)
}

plot.POSIXlt - function(x, y, xlab = , ...) {
if (missing(y)) plot.POSIXct(as.POSIXct(x), xlab=xlab, ...)
else plot.POSIXct(as.POSIXct(x), y=y, xlab=xlab, ...)
}

And try with:
x = Sys.time() + runif(100,1,7200)
plot(x)
plot(x,1:100)
plot(1:100,x)

plot(as.POSIXlt(x))
plot(as.POSIXlt(x),1:100)
plot(1:100,as.POSIXlt(x))


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

 -Original Message-
 From: Duncan Murdoch [mailto:[EMAIL PROTECTED] 
 Sent: 22 April 2008 14:24
 To: Sklyar, Oleg (MI London)
 Cc: R-devel@r-project.org
 Subject: Re: [Rd] graphics::Axis loosing S3/S4 class 
 attributes of 'x' in 2.7.0 RC
 
 On 4/22/2008 9:08 AM, Sklyar, Oleg (MI London) wrote:
  Duncan,
  
  looking further, what has changed from 2.6.2 into 2.7.0 are the 
  following two lines in plot.default, which I think were 
 logical before 
  and are not really logical now:
 
 I believe it is behaving as documented now, so the behaviour 
 is logical, even if it may not be convenient.  In your example
 
 x = Sys.time() + runif(100,1,7200) ## time over two hours, 
 POSIXct plot(x, 1:100) plot(1:100, x)
 
 the 1st works in 2.6.2 and 2.7.0 and the second only works in 2.6.2. 
 But the change below was designed to fix the case
 
 plot(x)
 
 which works in 2.7.0 and *not* in 2.6.2, so reverting the 
 change is not the way to address this.
 
 Duncan Murdoch
 
  
  plot.R: plot.default (2.6.2):
  if (axes) {
  localAxis(x, side=1, ...)
  localAxis(y, side=2, ...)
  }
  
  plot.R: plot.default (2.7.0):
  ...
  if (axes) {
  localAxis(xy$x, side=1, ...)
  localAxis(xy$y, side=2, ...)
  }
  
  The fact that xy.coords is called does not really matter.
  
  
  Dr Oleg Sklyar
  Technology Group
  Man Investments Ltd
  +44 (0)20 7144 3803
  [EMAIL PROTECTED]
  
  -Original Message-
  From: Duncan Murdoch [mailto:[EMAIL PROTECTED]
  Sent: 22 April 2008 13:01
  To: Sklyar, Oleg (MI London)
  Cc: R-devel@r-project.org
  Subject: Re: [Rd] graphics::Axis loosing S3/S4 class attributes of 
  '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
  debug messages
   in the code of Axis, Axis.default and plot.default in 
   graphics/R/axis.R and graphics/R/plot.R to print the 
 class of x, at 
   and y on plot. After recompiling R, what I see is that x 
 *lost* its 
   class attribute (at least for classes not known to 
 'graphics') in 
   Axis, called directly from plot.default and this could be
  the reason
   why R did not despatch on Axis.MyClass from my previous 
 post. This 
   happens for both S3 and S4 classes as in the code below!
  Funny enough,
   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 yourself?
  
   Is this really an intended behaviour? It looks very wrong to me!
  
  This is documented:  ?plot.default tells you to look at ?xy.coords 
  for details of how x and y are handled, and xy.coords says In any 
  other case, the 'x' argument is coerced to a vector and
returned as *y* component where the resulting 'x' is just the
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]
   ***
   Axis
   function (x = NULL, at = NULL, ..., side, labels = NULL) {
   cat(In Axis() class(x)=, class(x), ; class(at)=, 
 class(at),
   

[Rd] question about p-value implementation

2008-04-22 Thread Vincent Wolowski
Hello all,

I hope I have found the right place for my question.

There are different kinds of p-values for one-sided and two-sided
tests, for example mid p-value [1], minimum-likelihood p-value [2] or
conditional two-sided p-value [3].
I tried to find out what kind of p-value is implemented in R with
regard to the two-sided chi-square (function chisq.test()) and
Spearman rank test (function cor.test() with method=spearman), but I
could not determine this from the documentation or the source.
I would be thankful if someone with a better understanding could
provide an explanation.

[1] J. D. Gibbons, J. W. Pratt. P-Values: Interpretation and Methodology. 1975
[2] I. Rivals, L. Personnaz, L. Taing, M. C. Potier. Enrichment or
depletion of a GO category within a class of genes: which test?. 2006
[3] E. Kulinskaya. One two-sided p-values for non-symmetrical
distributions. 2007

Best regards,
Vincent

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] Bug in poly() (PR#11243)

2008-04-22 Thread russell-lenth
Full_Name: Russell Lenth
Version: 2.6.2
OS: Windows XP Pro
Submission from: (NULL) (128.255.132.36)


The poly() function allows a higher-degree polynomial than it should, when
raw=FALSE.

For example, consider 5 distinct 'x' values, each repeated twice.  we can fit a
polynomial of degree 8:

=
R x = rep(1:5, 2)
R y = rnorm(10)
R lm(y ~ poly(x, 8))

Call:
lm(formula = y ~ poly(x, 8))

Coefficients:
(Intercept)  poly(x, 8)1  poly(x, 8)2  poly(x, 8)3  poly(x, 8)4  poly(x, 8)5  
   -0.07790  0.58768  0.30147 -0.18237  0.64779 -0.0  
poly(x, 8)6  poly(x, 8)7  poly(x, 8)8  
   -0.22694 -0.07500  0.17235  
=

If we specify 'raw=TRUE' in the same example, we are limited (as we should) to a
degree-4 polynomial:

=
R lm(y ~ poly(x, 8, raw=TRUE))

Call:
lm(formula = y ~ poly(x, 8, raw = TRUE))

Coefficients:
(Intercept)  poly(x, 8, raw = TRUE)1  poly(x, 8, raw = TRUE)2  
 7.3958 -14.0150   8.2784  
poly(x, 8, raw = TRUE)3  poly(x, 8, raw = TRUE)4  poly(x, 8, raw = TRUE)5  
-1.9502   0.1597   NA  
poly(x, 8, raw = TRUE)6  poly(x, 8, raw = TRUE)7  poly(x, 8, raw = TRUE)8  
 NA   NA   NA  
=

We do get an error with an even higher degree:

=
R lm(y ~ poly(x, 10))
Error in poly(x, 10) : 'degree' must be less than number of points
=

Looking at the code for poly(), I think the problem is that it should check the
'rank' result from its call to qr().

[The above results are using Windows XP Pro, but I verified this bug under Linux
as well (x86_64, dual core).  It seems pretty obvious to me that this bug is not
platform-dependent.]

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] plot(x) in 2.7.0 (with y=NULL) proposed code correction

2008-04-22 Thread Martin Maechler
 OlegS == Sklyar, Oleg \(MI London\) [EMAIL PROTECTED]
 on Tue, 22 Apr 2008 17:34:24 +0100 writes:

OlegS Hi all:
OlegS following the previous discussion, it looks like plot(x) with y=NULL
OlegS still does not work correctly. If one tries for example plot(1:5) it
OlegS works, but already for plot(runif(100)) it does not. 

??? Not for me, with my propsal
{{maybe only in your too much modified version of R ??}

I've committed my proposal, and am interested in feedback, 
notably additional relevant examples.

Martin

OlegS I posted the proposed correction for plot.POSIXct and
OlegS plot.POSIXlt before. Please voice your opinions
OlegS whether the following fix for plot.default could be
OlegS reasonable? I include the full function and the diff.

(And both suffered from wraparounds)

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] graphics::Axis loosing S3/S4 class attributes of 'x' in 2.7.0 RC

2008-04-22 Thread Duncan Murdoch
There seem to be nonlinearities in the time-space continuum, so this 
message arrived several hours after Martin's, even though both have the 
same timestamp.  Please test his, and see if you can break it.  I'd 
guess not, it looks simple enough, but not too simple.

And for the future:

Please test the alpha/beta/RC releases!  The change we're talking about 
came fairly late in the process, but it was there for the last couple of 
weeks.  It would be easier for everyone if it had been corrected before 
release, rather than after.  It was announced on the RSS list, here:

http://developer.r-project.org/blosxom.cgi/R-2-7-branch/NEWS/2008/04/08#n2008-04-08

so it would really have helped if people who rely on special axis 
handling by Axis had tested the change after they'd seen that notice.

On 4/22/2008 10:26 AM, Sklyar, Oleg (MI London) wrote:
  Ok, so what's wrong with the following fix for plot(x)

The main thing that's wrong with it is that you don't explain what the 
changes are.  I can't believe that the error is specific to the POSIXct 
class, so it doesn't make sense that changes there would fix it in general.

Duncan Murdoch

  that would
 actually fix what needs to be fixed instead of changing plot.default?
 Fix means reverting plot.default in 2.7.0 to what it was (if testing in
 2.7.0, copy and paste the OLD plot.default into the .GlobalEnv):
 
 plot.POSIXct - function(x, y, xlab = , ...) {
 if (!missing(y)) {
 side = 1
 plotDef - function(x, y, xaxt, xlab, ...) plot.default(x, y,
 xaxt=n, xlab=xlab, ...)
 plotDef(x, y, xlab=xlab, ...)
 } else {
 side = 2
 plotDef - function(x, y, yaxt, xlab, ...) plot.default(x, y,
 yaxt=n, xlab=xlab, ...)
 plotDef(seq_along(x), x, xlab=xlab, ...)
 }
 ## trick to remove arguments intended for title() or plot.default()
 axisInt - function(x, type, main, sub, xlab, ylab, col, lty, lwd,
 xlim, ylim, bg, pch, log, asp, axes, frame.plot,
 ...)
 axis.POSIXct(side, x, ...)
 dots - list(...)
 axes - if(axes %in% names(dots)) dots$axes else TRUE
 xaxt - if(xaxt %in% names(dots)) dots$xaxt else par(xaxt)
 if(axes  xaxt != n) axisInt(x, ...)
 }
 
 plot.POSIXlt - function(x, y, xlab = , ...) {
 if (missing(y)) plot.POSIXct(as.POSIXct(x), xlab=xlab, ...)
 else plot.POSIXct(as.POSIXct(x), y=y, xlab=xlab, ...)
 }
 
 And try with:
 x = Sys.time() + runif(100,1,7200)
 plot(x)
 plot(x,1:100)
 plot(1:100,x)
 
 plot(as.POSIXlt(x))
 plot(as.POSIXlt(x),1:100)
 plot(1:100,as.POSIXlt(x))
 
 
 Dr Oleg Sklyar
 Technology Group
 Man Investments Ltd
 +44 (0)20 7144 3803
 [EMAIL PROTECTED] 
 
 -Original Message-
 From: Duncan Murdoch [mailto:[EMAIL PROTECTED] 
 Sent: 22 April 2008 14:24
 To: Sklyar, Oleg (MI London)
 Cc: R-devel@r-project.org
 Subject: Re: [Rd] graphics::Axis loosing S3/S4 class 
 attributes of 'x' in 2.7.0 RC
 
 On 4/22/2008 9:08 AM, Sklyar, Oleg (MI London) wrote:
  Duncan,
  
  looking further, what has changed from 2.6.2 into 2.7.0 are the 
  following two lines in plot.default, which I think were 
 logical before 
  and are not really logical now:
 
 I believe it is behaving as documented now, so the behaviour 
 is logical, even if it may not be convenient.  In your example
 
 x = Sys.time() + runif(100,1,7200) ## time over two hours, 
 POSIXct plot(x, 1:100) plot(1:100, x)
 
 the 1st works in 2.6.2 and 2.7.0 and the second only works in 2.6.2. 
 But the change below was designed to fix the case
 
 plot(x)
 
 which works in 2.7.0 and *not* in 2.6.2, so reverting the 
 change is not the way to address this.
 
 Duncan Murdoch
 
  
  plot.R: plot.default (2.6.2):
  if (axes) {
 localAxis(x, side=1, ...)
 localAxis(y, side=2, ...)
  }
  
  plot.R: plot.default (2.7.0):
  ...
  if (axes) {
 localAxis(xy$x, side=1, ...)
 localAxis(xy$y, side=2, ...)
  }
  
  The fact that xy.coords is called does not really matter.
  
  
  Dr Oleg Sklyar
  Technology Group
  Man Investments Ltd
  +44 (0)20 7144 3803
  [EMAIL PROTECTED]
  
  -Original Message-
  From: Duncan Murdoch [mailto:[EMAIL PROTECTED]
  Sent: 22 April 2008 13:01
  To: Sklyar, Oleg (MI London)
  Cc: R-devel@r-project.org
  Subject: Re: [Rd] graphics::Axis loosing S3/S4 class attributes of 
  '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
  debug messages
   in the code of Axis, Axis.default and plot.default in 
   graphics/R/axis.R and graphics/R/plot.R to print the 
 class of x, at 
   and y on plot. After recompiling R, what I see is that x 
 *lost* its 
   class attribute (at least for classes not known to 
 'graphics') in 
   Axis, called directly from plot.default and this could be
  the reason
   why R did not despatch on Axis.MyClass from my previous 
 post. This 
   happens for both S3 and S4 classes as in the code below!
  Funny enough,
   even integer was reset to 

Re: [Rd] graphics::Axis loosing S3/S4 class attributes of 'x' in 2.7.0 RC

2008-04-22 Thread Gabor Grothendieck
Its not clear to me at this point what and where the proposed
or already made change is but here
is a test that should produce a year/month style rather than
numeric style X axis:

library(zoo)
z - zoo(1:12, as.yearmon(2000 + 1:12/12))
plot(z)


On Tue, Apr 22, 2008 at 1:18 PM, Duncan Murdoch [EMAIL PROTECTED] wrote:
 There seem to be nonlinearities in the time-space continuum, so this
 message arrived several hours after Martin's, even though both have the
 same timestamp.  Please test his, and see if you can break it.  I'd
 guess not, it looks simple enough, but not too simple.

 And for the future:

 Please test the alpha/beta/RC releases!  The change we're talking about
 came fairly late in the process, but it was there for the last couple of
 weeks.  It would be easier for everyone if it had been corrected before
 release, rather than after.  It was announced on the RSS list, here:

 http://developer.r-project.org/blosxom.cgi/R-2-7-branch/NEWS/2008/04/08#n2008-04-08

 so it would really have helped if people who rely on special axis
 handling by Axis had tested the change after they'd seen that notice.

 On 4/22/2008 10:26 AM, Sklyar, Oleg (MI London) wrote:
   Ok, so what's wrong with the following fix for plot(x)

 The main thing that's wrong with it is that you don't explain what the
 changes are.  I can't believe that the error is specific to the POSIXct
 class, so it doesn't make sense that changes there would fix it in general.

 Duncan Murdoch


   that would
  actually fix what needs to be fixed instead of changing plot.default?
  Fix means reverting plot.default in 2.7.0 to what it was (if testing in
  2.7.0, copy and paste the OLD plot.default into the .GlobalEnv):
 
  plot.POSIXct - function(x, y, xlab = , ...) {
  if (!missing(y)) {
  side = 1
  plotDef - function(x, y, xaxt, xlab, ...) plot.default(x, y,
  xaxt=n, xlab=xlab, ...)
  plotDef(x, y, xlab=xlab, ...)
  } else {
  side = 2
  plotDef - function(x, y, yaxt, xlab, ...) plot.default(x, y,
  yaxt=n, xlab=xlab, ...)
  plotDef(seq_along(x), x, xlab=xlab, ...)
  }
  ## trick to remove arguments intended for title() or plot.default()
  axisInt - function(x, type, main, sub, xlab, ylab, col, lty, lwd,
  xlim, ylim, bg, pch, log, asp, axes, frame.plot,
  ...)
  axis.POSIXct(side, x, ...)
  dots - list(...)
  axes - if(axes %in% names(dots)) dots$axes else TRUE
  xaxt - if(xaxt %in% names(dots)) dots$xaxt else par(xaxt)
  if(axes  xaxt != n) axisInt(x, ...)
  }
 
  plot.POSIXlt - function(x, y, xlab = , ...) {
  if (missing(y)) plot.POSIXct(as.POSIXct(x), xlab=xlab, ...)
  else plot.POSIXct(as.POSIXct(x), y=y, xlab=xlab, ...)
  }
 
  And try with:
  x = Sys.time() + runif(100,1,7200)
  plot(x)
  plot(x,1:100)
  plot(1:100,x)
 
  plot(as.POSIXlt(x))
  plot(as.POSIXlt(x),1:100)
  plot(1:100,as.POSIXlt(x))
 
 
  Dr Oleg Sklyar
  Technology Group
  Man Investments Ltd
  +44 (0)20 7144 3803
  [EMAIL PROTECTED]
 
  -Original Message-
  From: Duncan Murdoch [mailto:[EMAIL PROTECTED]
  Sent: 22 April 2008 14:24
  To: Sklyar, Oleg (MI London)
  Cc: R-devel@r-project.org
  Subject: Re: [Rd] graphics::Axis loosing S3/S4 class
  attributes of 'x' in 2.7.0 RC
 
  On 4/22/2008 9:08 AM, Sklyar, Oleg (MI London) wrote:
   Duncan,
  
   looking further, what has changed from 2.6.2 into 2.7.0 are the
   following two lines in plot.default, which I think were
  logical before
   and are not really logical now:
 
  I believe it is behaving as documented now, so the behaviour
  is logical, even if it may not be convenient.  In your example
 
  x = Sys.time() + runif(100,1,7200) ## time over two hours,
  POSIXct plot(x, 1:100) plot(1:100, x)
 
  the 1st works in 2.6.2 and 2.7.0 and the second only works in 2.6.2.
  But the change below was designed to fix the case
 
  plot(x)
 
  which works in 2.7.0 and *not* in 2.6.2, so reverting the
  change is not the way to address this.
 
  Duncan Murdoch
 
  
   plot.R: plot.default (2.6.2):
   if (axes) {
  localAxis(x, side=1, ...)
  localAxis(y, side=2, ...)
   }
  
   plot.R: plot.default (2.7.0):
   ...
   if (axes) {
  localAxis(xy$x, side=1, ...)
  localAxis(xy$y, side=2, ...)
   }
  
   The fact that xy.coords is called does not really matter.
  
  
   Dr Oleg Sklyar
   Technology Group
   Man Investments Ltd
   +44 (0)20 7144 3803
   [EMAIL PROTECTED]
  
   -Original Message-
   From: Duncan Murdoch [mailto:[EMAIL PROTECTED]
   Sent: 22 April 2008 13:01
   To: Sklyar, Oleg (MI London)
   Cc: R-devel@r-project.org
   Subject: Re: [Rd] graphics::Axis loosing S3/S4 class attributes of
   '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
   debug messages
in the code of Axis, Axis.default and plot.default in
graphics/R/axis.R and graphics/R/plot.R to print the
  class 

Re: [Rd] plot(x) in 2.7.0 (with y=NULL) proposed code correction

2008-04-22 Thread Sklyar, Oleg (MI London)
To Martin:

sorry, you are right, my fault. Your SVN fix for axisLocal seems to
solve the problems for numerics.
However, the problem remains for POSIXct:

plot(Sys.time()+runif(100,1,7200))

(for me it plots time on y correctly, but labeling of index x axis and
xlab=Index are wrong/missing). I would assume that there is therefore
a problem in the current plot.POSIXct function. 

In fact, if one simply sets: plot.POSIXct = plot.default the result IS
correct! This is probably because POSIXct is numeric internally and axis
handling is performed correctly by your fix, i.e. strictly there is no
need for plot.POSIXct. For plot.POSIXlt, one could simply convert x into
POSIXct and call the default.

I do not think there will be many more standard R examples because the
problem was about calling one of the Axis.* methods and those are
defined for POSIX and Date classes only.

To Duncan:

I would be happy if I could test it before, I have recently started at
the current position and even now cannot access the R SVN directly due
to the company's internet connection policy.

The above working correctly for POSIXct with plot.default and not
working with plot.POSIXct was exactly the reason, why for me it is
logical to define Axis.MyClass rather than plot.MyClass.


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

 -Original Message-
 From: Martin Maechler [mailto:[EMAIL PROTECTED] 
 Sent: 22 April 2008 17:55
 To: Sklyar, Oleg (MI London)
 Cc: R-devel@r-project.org
 Subject: Re: plot(x) in 2.7.0 (with y=NULL) proposed code correction
 
  OlegS == Sklyar, Oleg \(MI London\) 
 [EMAIL PROTECTED]
  on Tue, 22 Apr 2008 17:34:24 +0100 writes:
 
 OlegS Hi all:
 OlegS following the previous discussion, it looks like 
 plot(x) with y=NULL
 OlegS still does not work correctly. If one tries for 
 example plot(1:5) it
 OlegS works, but already for plot(runif(100)) it does not. 
 
 ??? Not for me, with my propsal
 {{maybe only in your too much modified version of R ??}
 
 I've committed my proposal, and am interested in feedback, 
 notably additional relevant examples.
 
 Martin
 
 OlegS I posted the proposed correction for plot.POSIXct and
 OlegS plot.POSIXlt before. Please voice your opinions
 OlegS whether the following fix for plot.default could be
 OlegS reasonable? I include the full function and the diff.
 
 (And both suffered from wraparounds)
 


**
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@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] plot(x) in 2.7.0 (with y=NULL) proposed code correction

2008-04-22 Thread Duncan Murdoch
On 4/22/2008 1:37 PM, Sklyar, Oleg (MI London) wrote:
 To Martin:
 
 sorry, you are right, my fault. Your SVN fix for axisLocal seems to
 solve the problems for numerics.
 However, the problem remains for POSIXct:
 
 plot(Sys.time()+runif(100,1,7200))
 
 (for me it plots time on y correctly, but labeling of index x axis and
 xlab=Index are wrong/missing). I would assume that there is therefore
 a problem in the current plot.POSIXct function. 
 
 In fact, if one simply sets: plot.POSIXct = plot.default the result IS
 correct! This is probably because POSIXct is numeric internally and axis
 handling is performed correctly by your fix, i.e. strictly there is no
 need for plot.POSIXct. For plot.POSIXlt, one could simply convert x into
 POSIXct and call the default.
 
 I do not think there will be many more standard R examples because the
 problem was about calling one of the Axis.* methods and those are
 defined for POSIX and Date classes only.
 
 To Duncan:
 
 I would be happy if I could test it before, I have recently started at
 the current position and even now cannot access the R SVN directly due
 to the company's internet connection policy.

We do have daily binary builds, you don't need svn access.  I don't know 
if your company policy would allow you to download and install them, of 
course.  But if your company policy is not to allow you to test software 
that matters to the company, then you may have bigger problems than bad 
axis labels.

Duncan Murdoch

 
 The above working correctly for POSIXct with plot.default and not
 working with plot.POSIXct was exactly the reason, why for me it is
 logical to define Axis.MyClass rather than plot.MyClass.
 
 
 Dr Oleg Sklyar
 Technology Group
 Man Investments Ltd
 +44 (0)20 7144 3803
 [EMAIL PROTECTED] 
 
 -Original Message-
 From: Martin Maechler [mailto:[EMAIL PROTECTED] 
 Sent: 22 April 2008 17:55
 To: Sklyar, Oleg (MI London)
 Cc: R-devel@r-project.org
 Subject: Re: plot(x) in 2.7.0 (with y=NULL) proposed code correction
 
  OlegS == Sklyar, Oleg \(MI London\) 
 [EMAIL PROTECTED]
  on Tue, 22 Apr 2008 17:34:24 +0100 writes:
 
 OlegS Hi all:
 OlegS following the previous discussion, it looks like 
 plot(x) with y=NULL
 OlegS still does not work correctly. If one tries for 
 example plot(1:5) it
 OlegS works, but already for plot(runif(100)) it does not. 
 
 ??? Not for me, with my propsal
 {{maybe only in your too much modified version of R ??}
 
 I've committed my proposal, and am interested in feedback, 
 notably additional relevant examples.
 
 Martin
 
 OlegS I posted the proposed correction for plot.POSIXct and
 OlegS plot.POSIXlt before. Please voice your opinions
 OlegS whether the following fix for plot.default could be
 OlegS reasonable? I include the full function and the diff.
 
 (And both suffered from wraparounds)
 
 
 
 **
 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@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] plot(x) in 2.7.0 (with y=NULL) proposed code correction

2008-04-22 Thread Gabor Grothendieck
On Tue, Apr 22, 2008 at 1:45 PM, Duncan Murdoch [EMAIL PROTECTED] wrote:
  defined for POSIX and Date classes only.
 

zoo defines Axis methods for the yearmon and yearqtr classes and potentially
other time/date classes will need Axis methods.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] graphics::Axis loosing S3/S4 class attributes of 'x' in 2.7.0 RC

2008-04-22 Thread Duncan Murdoch
On 4/22/2008 1:29 PM, Gabor Grothendieck wrote:
 Its not clear to me at this point what and where the proposed
 or already made change is but here
 is a test that should produce a year/month style rather than
 numeric style X axis:
 
 library(zoo)
 z - zoo(1:12, as.yearmon(2000 + 1:12/12))
 plot(z)

It does.

Duncan Murdoch

 
 
 On Tue, Apr 22, 2008 at 1:18 PM, Duncan Murdoch [EMAIL PROTECTED] wrote:
 There seem to be nonlinearities in the time-space continuum, so this
 message arrived several hours after Martin's, even though both have the
 same timestamp.  Please test his, and see if you can break it.  I'd
 guess not, it looks simple enough, but not too simple.

 And for the future:

 Please test the alpha/beta/RC releases!  The change we're talking about
 came fairly late in the process, but it was there for the last couple of
 weeks.  It would be easier for everyone if it had been corrected before
 release, rather than after.  It was announced on the RSS list, here:

 http://developer.r-project.org/blosxom.cgi/R-2-7-branch/NEWS/2008/04/08#n2008-04-08

 so it would really have helped if people who rely on special axis
 handling by Axis had tested the change after they'd seen that notice.

 On 4/22/2008 10:26 AM, Sklyar, Oleg (MI London) wrote:
   Ok, so what's wrong with the following fix for plot(x)

 The main thing that's wrong with it is that you don't explain what the
 changes are.  I can't believe that the error is specific to the POSIXct
 class, so it doesn't make sense that changes there would fix it in general.

 Duncan Murdoch


   that would
  actually fix what needs to be fixed instead of changing plot.default?
  Fix means reverting plot.default in 2.7.0 to what it was (if testing in
  2.7.0, copy and paste the OLD plot.default into the .GlobalEnv):
 
  plot.POSIXct - function(x, y, xlab = , ...) {
  if (!missing(y)) {
  side = 1
  plotDef - function(x, y, xaxt, xlab, ...) plot.default(x, y,
  xaxt=n, xlab=xlab, ...)
  plotDef(x, y, xlab=xlab, ...)
  } else {
  side = 2
  plotDef - function(x, y, yaxt, xlab, ...) plot.default(x, y,
  yaxt=n, xlab=xlab, ...)
  plotDef(seq_along(x), x, xlab=xlab, ...)
  }
  ## trick to remove arguments intended for title() or plot.default()
  axisInt - function(x, type, main, sub, xlab, ylab, col, lty, lwd,
  xlim, ylim, bg, pch, log, asp, axes, frame.plot,
  ...)
  axis.POSIXct(side, x, ...)
  dots - list(...)
  axes - if(axes %in% names(dots)) dots$axes else TRUE
  xaxt - if(xaxt %in% names(dots)) dots$xaxt else par(xaxt)
  if(axes  xaxt != n) axisInt(x, ...)
  }
 
  plot.POSIXlt - function(x, y, xlab = , ...) {
  if (missing(y)) plot.POSIXct(as.POSIXct(x), xlab=xlab, ...)
  else plot.POSIXct(as.POSIXct(x), y=y, xlab=xlab, ...)
  }
 
  And try with:
  x = Sys.time() + runif(100,1,7200)
  plot(x)
  plot(x,1:100)
  plot(1:100,x)
 
  plot(as.POSIXlt(x))
  plot(as.POSIXlt(x),1:100)
  plot(1:100,as.POSIXlt(x))
 
 
  Dr Oleg Sklyar
  Technology Group
  Man Investments Ltd
  +44 (0)20 7144 3803
  [EMAIL PROTECTED]
 
  -Original Message-
  From: Duncan Murdoch [mailto:[EMAIL PROTECTED]
  Sent: 22 April 2008 14:24
  To: Sklyar, Oleg (MI London)
  Cc: R-devel@r-project.org
  Subject: Re: [Rd] graphics::Axis loosing S3/S4 class
  attributes of 'x' in 2.7.0 RC
 
  On 4/22/2008 9:08 AM, Sklyar, Oleg (MI London) wrote:
   Duncan,
  
   looking further, what has changed from 2.6.2 into 2.7.0 are the
   following two lines in plot.default, which I think were
  logical before
   and are not really logical now:
 
  I believe it is behaving as documented now, so the behaviour
  is logical, even if it may not be convenient.  In your example
 
  x = Sys.time() + runif(100,1,7200) ## time over two hours,
  POSIXct plot(x, 1:100) plot(1:100, x)
 
  the 1st works in 2.6.2 and 2.7.0 and the second only works in 2.6.2.
  But the change below was designed to fix the case
 
  plot(x)
 
  which works in 2.7.0 and *not* in 2.6.2, so reverting the
  change is not the way to address this.
 
  Duncan Murdoch
 
  
   plot.R: plot.default (2.6.2):
   if (axes) {
  localAxis(x, side=1, ...)
  localAxis(y, side=2, ...)
   }
  
   plot.R: plot.default (2.7.0):
   ...
   if (axes) {
  localAxis(xy$x, side=1, ...)
  localAxis(xy$y, side=2, ...)
   }
  
   The fact that xy.coords is called does not really matter.
  
  
   Dr Oleg Sklyar
   Technology Group
   Man Investments Ltd
   +44 (0)20 7144 3803
   [EMAIL PROTECTED]
  
   -Original Message-
   From: Duncan Murdoch [mailto:[EMAIL PROTECTED]
   Sent: 22 April 2008 13:01
   To: Sklyar, Oleg (MI London)
   Cc: R-devel@r-project.org
   Subject: Re: [Rd] graphics::Axis loosing S3/S4 class attributes of
   '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
   debug messages
in the code of Axis, Axis.default 

Re: [Rd] plot(x) in 2.7.0 (with y=NULL) proposed code correction

2008-04-22 Thread Bill Dunlap
On Tue, 22 Apr 2008, Martin Maechler wrote:

 I've committed my proposal, and am interested in feedback,
 notably additional relevant examples.

I tried the following test and the axes
looked right in 2.6.2 and the r45453
(right after your change to plot.R).
They looked bad (all were 2,4,6,8,10, not
1*pi,2*pi,3*pi) in r45390 (2008-04-19).


Axis.MyRadian - function(x = NULL, at = NULL, ...,
side, labels = NULL)
{
r - range(x)
npi - floor(r[1]/pi):ceiling(r[2]/pi)
at - npi * pi
labels - as.expression(lapply(
npi,function(i)substitute(i*pi, list(i=i
axis(side=side, at=at, labels=labels)
}
par(mfrow=c(2,2))
plot(structure(1:10, class=MyRadian), sin(1:10),
   main=n pi radians on x  axis)
plot(structure(1:10, class=MyRadian),
   main=n pi radians on y axis)
plot(structure(1:10, class=MyRadian),
   structure(10:1, class=MyRadian),
   main=n pi radians on both axes)
plot(1:10, 1:10, main=no pi's on either axis)
par(mfrow=c(2,2))



Bill Dunlap
Insightful Corporation
bill at insightful dot com
360-428-8146

 All statements in this message represent the opinions of the author and do
 not necessarily reflect Insightful Corporation policy or position.

__
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel