Warning: ignored non function "scale"
Peter Dalgaard BSA
p.dalgaard@biostat.ku.dk
24 Apr 1998 19:11:03 +0200
Paul Gilbert <pgilbert@bank-banque-canada.ca> writes:
>
> I've been working on a revised version of prcomp and princomp. Below is my
> current draft of prcomp, which is marginally different from V&R. I've added
> center and scale as optional arguments. However, scale causes the following:
>
> > zi _ prcomp(iris[,,2])
> Warning: ignored non function "scale"
>
> because scale is both a variable and a function. Is there any way to avoid this
> error message and still keep the name scale for both the argument and the name
> of the function?
There are several. One, which has been used in other parts of R is to
lengthen the formal argument a bit, e.g. "scale.it" which - since
there's no "..." part can be truncate to, say, "scale".
Another option is to explicitly fetch the function scale() using
get("scale","package:base") or get("scale",envir=.GlobalEnv). Anything
not including the functions local variables should do the trick.
Actually, I think that the first of the above get()s needs to be
get("scale",match("package:base",search()))
hmmm, shouldn't we make pos.to.env accept character variables?
> prcomp <- function(x, retx=TRUE, center=TRUE, scale=FALSE) {
> s <- svd(scale(x, center=center, scale=scale),nu=0)
> # rank <- sum(s$d > 0)
> rank <- sum(s$d > (s$d[1]*sqrt(.Machine$double.eps)))
> if (rank < ncol(x)) s$v <- s$v[,1:rank]
> s$d <- s$d/sqrt(max(1,nrow(x) -1))
> if(retx) list(sdev=s$d, rotation=s$v, x=x %*% s$v)
> else list(sdev=s$d, rotation=s$v)
> }
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._