[R] about body<-

From: ronggui <ronggui.huang_at_gmail.com>
Date: Sun, 30 Nov 2008 17:15:35 +0800


In body(fun, envir = environment(fun)) <- value, value can be an expression or a list of R expressions.

But it seems that value must be length-1 list (if it is a list), is it right?
> f2 <- function(x) {}
> body(f2) <- list(quote(x<- x^5),quote(return(y)))
Error in as.function.default(c(formals(fun), value), envir) :   invalid formal argument list for "function"

I want to construct a function by computing, what I do at this moment is as follows:

 >f <- function(x) {}
> body(f)[[2]] <- quote(x<- x^5)
> body(f)[[3]] <- quote(return(y))

Is there a better way to do this?

Thanks

-- 
HUANG Ronggui, Wincent
Tel: (00852) 3442 3832
PhD Candidate, City University of Hong Kong
http://ronggui.huang.googlepages.com/

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Sun 30 Nov 2008 - 09:22:26 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 30 Nov 2008 - 14:30:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive