[R] How to modify the body of a function?

Uwe Ligges ligges at statistik.tu-dortmund.de
Sun Jul 27 18:10:14 CEST 2014



On 27.07.2014 15:41, super wrote:
> Suppose that I had a function as below:
> f<-function() {
> return(1)
> }
> i want to change the body of f  to the form like this:
> f<-function(){
> 1
> function() {}
> }
> How can i do the task using body(f) or something else solutions?

See ?body:

  body(f) <- as.call(c(as.name("{"), expression(1, function(){})))

or parts of it by list indexing ("[[") ....

Best,
Uwe Ligges


> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list