Re: [R] environments

About this list Date view Thread view Subject view Author view

From: Alessio Farcomeni (axelio@tin.it)
Date: Fri 01 Jun 2001 - 16:52:20 EST


Message-Id: <3.0.6.32.20010601085220.00a60e20@box4.tin.it>


>Date: Wed, 30 May 2001 17:40:34 -0400
>From: Setzer.Woodrow@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@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


About this list Date view Thread view Subject view Author view

This archive was generated by hypermail 2b30 : Fri 22 Jun 2001 - 18:58:43 EST