Message-ID: <Pine.SOL.4.44.0304041730001.13101-100000@mspacman.gpcc.itd.umich.edu>
Date: 2003-04-04T22:35:56Z
From: Thomas W Blackwell
Subject: creating function bodies using body()
In-Reply-To: <OFD5A9F863.8E1E25FF-ON85256CFE.00785D4D@rtp.epa.gov>
Defining a function is much simpler than that:
tmpfun <- function(a, b=2)
{ z <- a = b
z^2 } # returns (a + b)^2
But maybe you want the advertised syntax to work. Please
pardon if I've misjudged the depth of your question. I've
never tried to use body().
- tom blackwell - u michigan medical school - ann arbor -
On Fri, 4 Apr 2003 Setzer.Woodrow at epamail.epa.gov wrote:
> I'm having trouble figuring out how to create a function using "body<-"
> (). The help file for body() says that the argument should be a list of
> R expressions. However if I try that I get an error:
>
> > tmpfun <- function(a, b=2){}
> > body(tmpfun) <- list(expression(z <- a + b),expression(z^2))
> Error in as.function.default(c(formals(f), value), envir) :
> invalid formal argument list for "function"
>
> Can someone give me a simple example for doing this? Thanks!
>
> R. Woodrow Setzer, Jr. Phone: (919) 541-0128
> Experimental Toxicology Division Fax: (919) 541-4284
> Pharmacokinetics Branch
> NHEERL B143-05; US EPA; RTP, NC 27711