.
In Zelig 5, the error was coming from a flag not set to silent in
“wrappers.R” and was not affecting further code execution. So
mf <- try(eval(mf, environment()))
is now
mf <- try(eval(mf, environment()), silent = TRUE)
Running your example, we get:
rm(list = ls())
test_function <- function() {
data(cars)
x <- cars
zelig(dist ~ speed, data = x, model = "ls", cite = FALSE)}
test_function()
## Model:
## $by
## [1] 1
##
##
## Call:
## stats::lm(formula = formula, data = .)
##
## Coefficients:
## (Intercept) speed
## -17.579 3.932
##
## Next step: Use 'setx' method
(
)
Best regards,
Christine
On Tue, Oct 21, 2014 at 8:50 AM, David Kane <dave.kane(a)gmail.com> wrote:
I *believe* that there is a bug in Zelig's
scoping. This exists on the
cran version (from where it bit me) but also in the development version.
packageVersion("Zelig")
[1]
"5.0.2"
Interactively, the Zelig demo works fine:
data(cars)
x <- cars
zelig(dist ~ speed, data = x, model = "ls")
How to cite this model in
Zelig:
Kosuke Imai, Gary King, and Olivia Lau. 2007.
...
Note that assigning cars to x and then passing x as the argument to data
is needed to demonstrate the bug. The problem comes when we wrap this code
within a function.
rm(list = ls())
test_function <- function(){data(cars); x <- cars; zelig(dist ~ speed,
data
= x, model = "ls")}
test_function()
Error in callSuper(formula
= formula, data = data, ..., weights = NULL, :
object 'x' not found
How to cite this model in Zelig:
Kosuke Imai, Gary King, and Olivia Lau. 2007.
...
It is the Error above that is the problem. (Strangely, the code still
seems to work in the development version after issuing that Error message.
In the CRAN version, it does not.)
Note that you need to keep your workplace clean to see this clearly. See
the rm(list = ls()) above. If you don't issue this command (after doing the
interactive code), you don't get any error:
> rm(list = ls())
data(cars)
x <- cars
zelig(dist ~ speed, data = x, model = "ls")
How to cite this model in
Zelig:
Kosuke Imai, Gary King, and Olivia Lau. 2007.
...
test_function <- function(){data(cars); x
<- cars; zelig(dist ~ speed,
data = x, model = "ls")}
test_function()
How to cite this model in
Zelig:
Kosuke Imai, Gary King, and Olivia Lau. 2007.
...
No Error because Zelig finds x in the global environment. Of course, it
should be using the local x.
My colleague thinks that, in the CRAN version, this snippet of code is
wrong:
divided.data <- eval(call("multi.dataset", substitute(data)))
But I am not enough of an R guru to determine the cause of the bug.
Thanks,
Dave Kane
-
--
Zelig Mailing List, served by HUIT
Send messages: zelig(a)lists.gking.harvard.edu
[un]subscribe Options:
http://lists.gking.harvard.edu/mailman/listinfo/zelig
Zelig program information:
http://gking.harvard.edu/zelig/
Zelig mailing list
Zelig(a)lists.gking.harvard.edu
To unsubscribe from this list or get other information:
https://lists.gking.harvard.edu/mailman/listinfo/zelig