From saikat at stat.wisc.edu  Thu Aug  7 11:09:12 2003
From: saikat at stat.wisc.edu (Saikat DebRoy)
Date: Thu Aug  7 16:08:53 2003
Subject: [Rd] model.frame() call from inside a function (PR#3671)
In-Reply-To: <x2znilx4uz.fsf@biostat.ku.dk>
Message-ID: <B88B3B32-C8E0-11D7-AF59-0003931A3C9E@stat.wisc.edu>

On Thursday, Aug 7, 2003, at 04:13 US/Eastern, Peter Dalgaard BSA wrote:

>
> [[ I did discover yesterday (or maybe I was just reminded...) that we
> even have nonstandard nonstandard evaluation rules in some places
> (nls() seems to evaluate its model formula in the global environment
> even if it is given explicitly within a function:
>
>   f <- function() {
>     g <- function(a,x) exp(-a*x)
>     nls(y~g(a,x),start=list(a=.1))
>   }
>   x <- 1:10
>   y <- exp(-.12*x)+rnorm(10,sd=.001)
>   f()
>   Error in eval(expr, envir, enclos) : couldn't find function "g"
>
> Argh...]]
>

Given that I am, for better or worse,  responsible for a large portion 
of the code in nls, I should make it clear that I did not understand 
the nonstandard evaluation rule in those days and so any nonstandrad 
nonstandrad rule used there is a bug. Now that I understand these 
things a little, I can see that nls does a few things wrong. I think 
the following patch mostly fixes them.


-------------- next part --------------


[Rd] model.frame() call from inside a function (PR#3671)
Saikat DebRoy