Tks for your opinions, let me describe the background for my question:
The orignal purpose is to call the function which defined in anothor function, e.g.
f1<-function(){
x<-1
f2<-function(x)
{x}
f3<-function(){
1+1
}
a<-1
return(x+a)
}
The real function  f1  may be very long, And i know there is a function named f3 defined in f1. f3 is useful for me.  For some reason, i can't copy and paste f3's source code manually.
So, with the solution for modifying the body of a  function, i can do the original task as below:


oldbody<-body(f1)
newbody<-bquote({.(redefine);.(oldbody);.(addstuff)},list(redefine=quote(return<-function(x){x}),oldbody=oldbody,addstuff=quote(function(){})))
body(f1)<-newbody
closure<-f1()
ls(environment(closure))
environment(closure)$f3


Is there a easy way to do my original task?









At 2014-07-27 09:41:49, "super" <desolator88@163.com> 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?
>	[[alternative HTML version deleted]]
>
>______________________________________________
>R-help@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.

	[[alternative HTML version deleted]]

