Formula syntax is different from regular syntax, it is "quoted" and
not evaluated in the same way as regular commands (otherwise operations like
'+' and '-' would do very different things).
For what you are trying to do, I would suggest creating the formula as a string
using paste or sprintf, then use as.formula on that string. You can also use
the substitute function, but that tends to be a bit more complicated.
--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Patrick McKann
> Sent: Wednesday, January 05, 2011 8:26 AM
> To: r-help at r-project.org
> Subject: [R] get() within a command, specifically lmer
>
> Hello all. Why doesn't this work?
>
>
d=data.frame(y=rpois(10,1),x=rnorm(10),z=rnorm(10),grp=rep(c('a','b'),e
> ach=5))
> library(lme4)
> model=lmer(y~x+z+(1|grp),family=poisson,data=d)
> update(model,~.-z)###works, removes z
> var='z'
> update(model,~.-get(var))##doesn't remove z
> update(model,~. -get(var,pos=d))###doesn't remove z
>
> I am trying to remove z from the model in the update, but I can't do it
> using get(), which is what I would like to do for a more complicated
> program. There's something about environments and get() that I
don't
> understand.
>
> Any suggestions?
>
> Thanks.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.