[R] creating function bodies using body()

Setzer.Woodrow@epamail.epa.gov Setzer.Woodrow at epamail.epa.gov
Sat Apr 5 00:05:59 CEST 2003

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

More information about the R-help mailing list