From tlumley at u.washington.edu  Thu Aug  7 08:14:35 2003
From: tlumley at u.washington.edu (Thomas Lumley)
Date: Thu Aug  7 16:14:28 2003
Subject: [Rd] model.frame() call from inside a function (PR#3671)
In-Reply-To: <x2znilx4uz.fsf@biostat.ku.dk>
Message-ID: <Pine.A41.4.44.0308070713060.77846-100000@homer22.u.washington.edu>

On 7 Aug 2003, 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...]]


This is the same phenomenon that is documented for lattice graphics and
for lme in my notes on nonstandard evaluation rules.  I think it *is* a
bug.

	-thomas


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