[R] about body<-

ronggui ronggui.huang at gmail.com
Sun Nov 30 10:15:35 CET 2008


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/



More information about the R-help mailing list