Hi there, I wrote a function that wraps MASS::boxcox as:
bc <- function(vec) { lam <- boxcox(lm(vec ~ 1)) lam <- lam$x[which.max(lam$y)] (vec^lam - 1)/lam } When I invoke it as: > x <- runif(20) > bc(x) Error in eval(predvars, data, env) : object 'vec' not found I have googled, and rewrote the above function as: bc <- function(vec) { dat <<- data.frame(vec = vec) lam <- boxcox(lm(vec ~ 1, dat)) lam <- lam$x[which.max(lam$y)] rm(dat, envir = .GlobalEnv) (vec^lam - 1)/lam } It works. But, I am wondering why MASS::boxcox have to wrap in such way that have to use the data in .GlobalEnv. Best, Jinsong [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.