[R] unexpected behaviour of 'curve' function

2004-11-26 Thread Guazzetti Stefano
Dear all, 

curve(x^3*(1-x)^7, from = 0, to = 1)

works as  expected but, omitting the xlim or the to 
and from arguments and calling curve more than once:

par(mfrow = c(2,2))
for (i in 1:4)
curve(x^3*(1-x)^7)

gives an expected (al least to me) result.
Note also that a pu object is returned by curve

 pu
[1] -0.1802445  1.1802445

The behaviour is reproducible with both  R 2.0.0
and R 2.0.1

I can see that a promise of evaluation of pu
is made within curve but I cannot understand completely
what happens.

Thanks in advance, 

Stefano Guazzetti


platform i386-pc-mingw32
arch i386   
os   mingw32
system   i386, mingw32  
status  
major2  
minor0.0
year 2004   
month10 
day  04 
language R

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] unexpected behaviour of 'curve' function

2004-11-26 Thread Peter Dalgaard
Guazzetti Stefano [EMAIL PROTECTED] writes:

 Dear all, 
 
 curve(x^3*(1-x)^7, from = 0, to = 1)
 
 works as  expected but, omitting the xlim or the to 
 and from arguments and calling curve more than once:
 
 par(mfrow = c(2,2))
 for (i in 1:4)
 curve(x^3*(1-x)^7)
 
 gives an expected (al least to me) result.
 Note also that a pu object is returned by curve
 
  pu
 [1] -0.1802445  1.1802445
 
 The behaviour is reproducible with both  R 2.0.0
 and R 2.0.1
 
 I can see that a promise of evaluation of pu
 is made within curve but I cannot understand completely
 what happens.

I think the upshot is just that it is taking the from and to from
par(usr) from the previous plot and every time you do so, it expands
a little (about 4%). Notice that it does not happen if you do this:

 par(mfrow = c(2,2), xaxs=i)
 for (i in 1:4)
curve(x^3*(1-x)^7)

Having pu end up in the global environment looks like a bug in
delay() but I don't think it has any influence on this particular
effect. 


-- 
   O__   Peter Dalgaard Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics 2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark  Ph: (+45) 35327918
~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] unexpected behaviour of 'curve' function

2004-11-26 Thread Duncan Murdoch
On 26 Nov 2004 12:27:35 +0100, Peter Dalgaard
[EMAIL PROTECTED] wrote:

Guazzetti Stefano [EMAIL PROTECTED] writes:

 Dear all, 
 
 curve(x^3*(1-x)^7, from = 0, to = 1)
 
 works as  expected but, omitting the xlim or the to 
 and from arguments and calling curve more than once:
 
 par(mfrow = c(2,2))
 for (i in 1:4)
 curve(x^3*(1-x)^7)
 
 gives an expected (al least to me) result.
 Note also that a pu object is returned by curve
 
  pu
 [1] -0.1802445  1.1802445
 
 The behaviour is reproducible with both  R 2.0.0
 and R 2.0.1
 
 I can see that a promise of evaluation of pu
 is made within curve but I cannot understand completely
 what happens.

I think the upshot is just that it is taking the from and to from
par(usr) from the previous plot and every time you do so, it expands
a little (about 4%). 

It's not documented what from and to will be when add=FALSE, so
this isn't strictly speaking a bug, but I'd say it's undesirable
behaviour.  I'd much rather see from=0 and to=1 in this case.

 Notice that it does not happen if you do this:

 par(mfrow = c(2,2), xaxs=i)
 for (i in 1:4)
curve(x^3*(1-x)^7)

Having pu end up in the global environment looks like a bug in
delay() but I don't think it has any influence on this particular
effect. 

That's a pretty serious bug in delay().  It's been there at least
since 1.9.1.

Duncan Murdoch

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] unexpected behaviour of 'curve' function

2004-11-26 Thread Duncan Murdoch
On Fri, 26 Nov 2004 18:48:45 -0500, Duncan Murdoch
[EMAIL PROTECTED] wrote:

On 26 Nov 2004 12:27:35 +0100, Peter Dalgaard
[EMAIL PROTECTED] wrote:

Having pu end up in the global environment looks like a bug in
delay() but I don't think it has any influence on this particular
effect. 

That's a pretty serious bug in delay().  It's been there at least
since 1.9.1.

Oops, not a bug, behaving as documented (but maybe a design flaw)?
delay() is documented as defaulting to the global environment.
curve() should have used env=environment().

Duncan Murdoch

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] unexpected behaviour of 'curve' function

2004-11-26 Thread Peter Dalgaard
Duncan Murdoch [EMAIL PROTECTED] writes:

 Oops, not a bug, behaving as documented (but maybe a design flaw)?
 delay() is documented as defaulting to the global environment.
 curve() should have used env=environment().

Or not used delay() at all. That code looks a bit warped.

AFAICT, you could have 'from' defaulting to lims[1] and 'to' to
lims[2], then in the body let 

if(missing(from) || missing(to))
lims - if(missing(xlim)) 
if (par(xlog)) 
10 ^ par(usr)[1:2] 
else 
 par(usr)[1:2] 
else
xlim

and get the same result (notwithstanding that you probably don't want
to use par(usr) in that way)

-- 
   O__   Peter Dalgaard Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics 2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark  Ph: (+45) 35327918
~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html