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

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to