Skip to content

Warning: ignored non function "scale"

2 messages · Paul Gilbert, Peter Dalgaard

#
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:
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?

Paul Gilbert
______

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)
}


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
Paul Gilbert <pgilbert@bank-banque-canada.ca> writes:
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?