[Rd] mva:princomp.default not set correctly (PR#3168)

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Jun 2 17:54:16 MEST 2003


This is not about princomp.default at all!  That snippet of code does not
appear there.

Please do check against the S-PLUS original of biplot.default: this is in
biplot.default.  I very much doubt if you understand the intentions
(not that I do either).

On Mon, 2 Jun 2003 irwin at imcs.rutgers.edu wrote:

> Full_Name: Andrew Irwin
> Version: 1.7.0
> OS: Win98
> Submission from: (NULL) (165.230.175.97)
> 
> 
> 
> It is impossible to set both xlim and ylim in princomp or princomp.default.
> 
> For example
>   data(USArrests)
>   biplot(princomp(USArrests))
> works fine, but
>   biplot(princomp(USArrests), xlim=c(-0.4, 0.4), ylim=c(-0.5,0.4) )
> does not do what I would expect -- the ylim gets ignored.

Since when were your expectations the determinant of a bug?

> The offending bit of code from mva:princomp.default seems to be
> 
>     if (missing(xlim) && missing(ylim)) 
>         xlim <- ylim <- rangx1 <- rangx2 <- range(rangx1, rangx2)
>     else if (missing(xlim)) 
>         xlim <- rangx1
>     else ylim <- rangx2
> 
> 
> This if .. else if .. else clause is not written the way I think it should be
> written.  The else clause should only be executed if ylim is missing, but it
> will be executed if xlim and ylim are both present.
> 
> Suggested rewrite:
> 
>     if (missing(xlim) && missing(ylim)) 
>         xlim <- ylim <- rangx1 <- rangx2 <- range(rangx1, rangx2)
>     else if (missing(xlim)) 
>         xlim <- rangx1
>     else if (missing(ylim))
>         ylim <- rangx2
> 
> ifelse clause might be better, but less readable.
> 
> Cheers,
> 
> Andrew
> 
> ______________________________________________
> R-devel at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-devel
> 

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list