[R] Wrong environment when evaluating and expression?
Joshua Wiley
jwiley.psych at gmail.com
Mon Jul 4 10:11:57 CEST 2011
Hi All,
I have constructed two expressions (e1 & e2). I can see that they are
not identical, but I cannot figure out how they differ.
###############
dat <- mtcars
e1 <- expression(with(data = dat, lm(mpg ~ hp)))
e2 <- as.expression(substitute(with(data = dat, lm(f)), list(f = mpg ~ hp)))
str(e1)
str(e2)
all.equal(e1, e2)
identical(e1, e2) # false
eval(e1)
eval(e2)
################
The context is trying to use a list of formulae to generate several
models from a multiply imputed dataset. The package I am using (mice)
has methods for with() and that is how I can (easily) get the pooled
results. Passing the formula directly does not work, so I was trying
to generate the entire call and evaluate it as if I had typed it at
the console, but I am missing something (probably rather silly).
Thanks,
Josh
--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/
More information about the R-help
mailing list