environments
Date: Wed, 30 May 2001 17:40:34 -0400
From: Setzer.Woodrow at epamail.epa.gov
Subject: [R] environments
I would like to be able, inside a function, to create a new function, and
use it as part of a formula as an argument to, say, gnls or nlme. for
example:
MyTop <- function(data=dta) {
Cexp <- function(dose,A,B,m){...}
Model <- as.formula(paste("y","~ Cexp(",paste(formals(Cexp),collapse
=", "),")"))
MyCall <- call("gnls",Model,dta,...)
eval(MyCall)
}
When I actually try this, I get an error return with the message "Cexp not
found". Is there a way around this? I know I can use "Cexp <<- ...", but
I'm trying to find a "clean" solution. Thanks.
I don't have your problems, usually I can define functions inside functions
without problems. Maybe it's the R version... However, perhaps you can
simply define the function Cexp out of MyTop, thus having it visible
"globally". Try this:
Cexp <- function(dose,A,B,m){...}
MyTop <- function(data=dta) {
Model <- as.formula(paste("y","~ Cexp(",paste(formals(Cexp),collapse
=", "),")"));
MyCall <- call("gnls",Model,dta,...);
eval(MyCall)
}
Bye,
Alessio
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._