I'm in a bit beyond my depth with environments and such.
The environment of a particular function, which I've set
so it should have the things it needs, seems to be getting
"lost" at some point during a call sequence.
It's hard to come up with a _simple_ reproducible
example, although if anyone's sufficiently interested I
can post the package somewhere -- with the package installed,
it's only a few steps to reproduce the example.
I end up, deep in the process of trying to compute
a likelihood profile, with the following situation:
I want to evaluate "call":
call
mle2(minuslogl = function (lmu = NULL, ltheta = NULL)
{
if (!is.null(parameters)) {
pars <- unlist(as.list(match.call())[-1])
for (i in seq(along = parameters)) {
assign(vars[i], mmats[[i]] %*% pars[vpos[[i]]])
}
}
arglist1 <- lapply(arglist1, eval, envir = data, enclos
sys.frame(sys.nframe()))
r <- -sum(do.call(ddistn, arglist1))
r
}, start = list(lmu = -2.16316747342067, ltheta = 2.30970721353114),
fixed = list(lmu = -2.18543734742826))
The function appears to have the right stuff in its
environment:
Browse[1]> ls(envir=environment(call$minuslogl))
[1] "arglist1" "ddistn" "mmats"
"vars" "vpos"
But evaluating the call, even with the environment
set to the environment of the internal function, doesn't
seem to work
Browse[1]> eval(call,envir=environment(call$minuslogl))
Error during wrapup: object "arglist1" not found
The full stack looks like this:
> profile(m0f,skiperrs=FALSE)
Error in is.vector(X) : object "arglist1" not found
Enter a frame number, or 0 to exit
1: profile(m0f, skiperrs = FALSE)
2: profile(m0f, skiperrs = FALSE)
3: .local(fitted, ...)
4: onestep(step)
5: eval.parent(call, 2)
6: eval(expr, p)
7: eval(expr, envir, enclos)
8: mle2(minuslogl = function (lmu = NULL, ltheta = NULL)
9: optim(start, objectivefunction, method = method, hessian = TRUE, ...)
10: function (par)
11: fn(par, ...)
12: do.call("minuslogl", args, envir = environment(minuslogl))
13: minuslogl(ltheta = 2.30970721353114, lmu = -2.18543734742826)
14: lapply(arglist1, eval, envir = data, enclos = sys.frame(sys.nframe()))
15: is.vector(X)
Selection:
Anyone have any ideas/directions/leading questions?
cheers
Ben Bolker
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
Url :
https://stat.ethz.ch/pipermail/r-devel/attachments/20070214/4e178bd4/attachment.bin