Skip to content

unexpected behaviour of 'curve' function

5 messages · Guazzetti Stefano, Peter Dalgaard, Duncan Murdoch

#
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
[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                  
major    2              
minor    0.0            
year     2004           
month    10             
day      04             
language R
#
"Guazzetti Stefano" <Stefano.Guazzetti at ausl.re.it> writes:
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.
#
On 26 Nov 2004 12:27:35 +0100, Peter Dalgaard
<p.dalgaard at biostat.ku.dk> wrote:

            
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.
That's a pretty serious bug in delay().  It's been there at least
since 1.9.1.

Duncan Murdoch
#
On Fri, 26 Nov 2004 18:48:45 -0500, Duncan Murdoch
<murdoch at stats.uwo.ca> wrote:

            
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
#
Duncan Murdoch <murdoch at stats.uwo.ca> writes:
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)