update() can not find objects (PR#1861)

tlumley@u.washington.edu tlumley@u.washington.edu
Thu, 1 Aug 2002 23:14:52 +0200 (MET DST)


On Thu, 1 Aug 2002, Yi-Xiong Zhou wrote:

> Thanks Peter. This does work for formula. However, it failed to a function
> call. Here is another test script:
>
> ################# begin test ###############
> fun1 <- function() {
>    x <- matrix(rnorm(500), 20,25)
>    oo <- fun3(x)
>    print("step 1")
>    update(oo)
>    print("first update success.")
>    fun2(oo)
> }
>
> fun2 <- function(gg) {
>    update(gg)
>    print("second update success.")
> }
>
> fun3 <- function(aa) {
>    oo <- list(x=aa, call=match.call())
>    oo
> }
>
> fun1()
> ############### end test ############
>
> The error message is
>
> [1] "step 1"
> [1] "first update success."
> Error in fun3(aa = x) : Object "x" not found

Yes, but this isn't supposed to work, and can't.

In the first place update() is supposed to work on models, not on
arbitrary objects.

In the second place, the object you are returning contains no information
about where it was created, so it's not possible for update to work out
the correct environment.  In this case the correct environment happens to
be parent.frame(2), but there's no reason why this should be true in
general.


When the object is a model with a formula it does carry information about
where it was defined, so update() can look there.  Your first example
should have worked, and the fact that it didn't is a bug (though arguably
just a wishlist bug).  This new example shouldn't work.


	-thomas



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._