[R] unexpected behaviour of 'curve' function

Peter Dalgaard p.dalgaard at biostat.ku.dk
Fri Nov 26 12:27:35 CET 2004


"Guazzetti Stefano" <Stefano.Guazzetti at ausl.re.it> 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
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list