I'm having difficulty with an environmental issue: I have an additive model fitting function
with a typical call that looks like this:

require(quantreg)
n <- 100
x <- runif(n,0,10)
y <- sin(x) + rnorm(n)/5
d <- data.frame(x,y)
lam <- 2

        f <- rqss(y ~ qss(x, lambda = lam), data = d)

this is fine when invoked as is; x and y are found in d, and lam is found the .GlobalEnv, or at least this is how I understand it. Now, I'd like to have a function say,

        h <- function(lam)
                AIC(rqss(y ~ qss(x, lambda = lam), data = d))

but now,  if I do:

        rm(lam)
        h(1)
Error in qss1(x, constraint = constraint, lambda = lambda, dummies = dummies, :
  object "lam" not found

worse, if there is a "lam" in the .GlobalEnv it is used instead of the argument specified to h(). If I remove the data=d argument in the function definition then lam is passed correctly. presumably because data defaults to parent.env(). I recognize that this is probably an elementary confusion on my part, but my understanding of environments is very limited.
I did read  the entry for FAQ 7.12,  but I'm still unenlightened.

url:    www.econ.uiuc.edu/~roger                Roger Koenker
email   rkoen...@uiuc.edu                       Department of Economics
vox:    217-333-4558                            University of Illinois
fax:    217-244-6678                            Champaign, IL 61820

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to