[R] dropterm in a function

Thomas Lumley tlumley at u.washington.edu
Fri Oct 4 16:22:55 CEST 2002

On Fri, 4 Oct 2002, [iso-8859-1] Göran Broström wrote:

> I'm trying to use 'dropterm' (from MASS) in a function along the lines
> run <- function(dat){
>   fit <- (something)(Y ~ (something), data = dat)
>   lr <- dropterm(fit, test = "Chisq")
>   return(fit, lr)
> }
> but running 'run' I get (those scoping rules again...?)
> Error in terms.formula(formula, special, data = data) :
>         Object "dat" not found
> This works fine at the command line. Can I send 'dat' to 'dropterm'
> somehow, or what should I do?

What is "something"? If "something" is lm or glm this works for me. I
would expect it not to work for lme().

This isn't precisely a scoping rules issue, but a nonstandard evaluation
rules one.  Functions using model formulas have to do strange things to
evaluate variables, and they don't always work consistently.


r-help 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-help-request at stat.math.ethz.ch

More information about the R-help mailing list