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

Saikat DebRoy saikat at stat.wisc.edu
Thu Aug 7 11:09:12 MEST 2003


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 --------------



More information about the R-devel mailing list