[R] problem with nlme, environments, and packages

Greg Hather ghather at gmail.com
Wed Jun 17 02:52:18 CEST 2015


Thank you, Duncan!  Your suggestion worked!

Greg

On Tue, Jun 16, 2015 at 12:20 PM, Duncan Murdoch <murdoch.duncan at gmail.com>
wrote:

> On 16/06/2015 10:34 AM, Greg Hather wrote:
> > Hi Duncan,
> >
> > I checked the global environment, and it was empty, so I think that
> > rules out the second possibility.  I posted a tarball at
> >
> >
> https://drive.google.com/file/d/0B8hBX90jtuLcaGtOUktqV2V4UUU/view?usp=sharing
> >
> > Thank you for your help!
> >
> > Greg
> >
>
> The problem is that nlme does a lot of evaluation of formula objects
> without taking their associated environment into account.  Fixing it
> doesn't look easy, because the evaluation happens in a lot of places.
>
> One workaround is to put the appropriate environment(s) on the search
> list before calling nlme().  This isn't perfect, because the search
> order will be wrong, but it will get you something.
>
> For example, your main_function could be
>
> main_function <- function(x){
>
>   library(nlme)
>   attach(parent.env(env=environment()))
>   result <- nlme(height ~ SSasymp(age, Asym, R0, lrc) +
> nonlinear_function(age),
>                  data = Loblolly,
>                  fixed = Asym + R0 + lrc ~ 1,
>                  random = Asym ~ 1,
>                  start = c(Asym = 103, R0 = -8.5, lrc = -3.3))
>   detach()
>   result
> }
>
> Duncan
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list