[R] substitute question
Thomas Lumley
tlumley at u.washington.edu
Thu Mar 18 20:29:39 CET 2004
On Thu, 18 Mar 2004, Gabor Grothendieck wrote:
>
> Tony, Thomas. Thanks for your help. Your comments were very
> useful.
>
> Unfortunately, my next step gives me a new round of problems.
>
> The following is the same as the last example except that instead
> of hard coding the function into the expression I wanted to
> pass it to the expression. It seems like one has to do a double
> substitute to get this effect but I am having problems getting this
> to work.
>
The problem is that f is a function, not an expression. You need to work
with body(f)
Either
> f<-function(){a+1}>
body(f)<-do.call("substitute",list(body(f),list(a=quote(b))))> f
function ()
{
b + 1
}
or
> f<-function(){a+1}
> body(f)<-eval(substitute(substitute(expr,list(a=quote(b))),list(expr=body(f))))
> f
function ()
{
b + 1
}
-thomas
More information about the R-help
mailing list