[R] Question concerning library function "nlme" and lexical scoping

Jens_Praestgaard@hgsi.com Jens_Praestgaard at hgsi.com
Wed Mar 10 17:13:47 CET 2004




I am running into problems calling the library function nlme from within
another function.  Basically,the following function (with v a list
containing data and initialization values)

> testfunc
function(dat=v) {
test<-nlsList(result~a+(b-a)/(1+(conc/(c+z*cdiff))^d)
|rep,start=dat$init,data=dat$mixeddat)
return(nlme(test,random=b~1))
}
 produces the error message

Error in eval(expr, envir, enclos) : Object "dat" not found.

However, if the assignment dat<-v is done globally, then testfunc()
produces the desired mixed model analysis.

As I understand lexical scoping, the nlme function should take the value of
"dat" from the calling environment through its "data = sys.frame(sys.parent
())" argument. Instead it seems to only recognize dat if it is defined
globally.

Thank you.

Jens Praestgaard
Human Genome Sciences




More information about the R-help mailing list