[R] unexpected behaviour of 'curve' function

Duncan Murdoch murdoch at stats.uwo.ca
Sat Nov 27 00:48:45 CET 2004


On 26 Nov 2004 12:27:35 +0100, Peter Dalgaard
<p.dalgaard at biostat.ku.dk> wrote:

>"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%). 

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




More information about the R-help mailing list