[Rd] turning expression object to function

2006-12-18 Thread Antonio, Fabio Di Narzo
Dear all, I have the following problem. Given an expression object 'expr' containing a certain set of symbols (say 'a', 'b', 'c'), I would like to translate the expression object in an R function of, say, 'a', programmatically. Here an example of what I mean. Given: expr - expression(a+b+c) a

Re: [Rd] turning expression object to function

2006-12-18 Thread Marc Schwartz
On Mon, 2006-12-18 at 19:06 +0100, Antonio, Fabio Di Narzo wrote: Dear all, I have the following problem. Given an expression object 'expr' containing a certain set of symbols (say 'a', 'b', 'c'), I would like to translate the expression object in an R function of, say, 'a',

Re: [Rd] turning expression object to function

2006-12-18 Thread Gabor Grothendieck
Here is one possibility. It does not use the second argument in your function call but instead assumes the arguments of the output function are those variables in the expression that have not been assigned in the list L in the order encountered. library(gsubfn) asFun - function(e, L = NULL, env

Re: [Rd] turning expression object to function

2006-12-18 Thread Tony Plate
This is what I tried, and it seemed to work, but maybe others can give better ideas, and also explain why the first attempt to assign the formal arguments didn't work (but the second did.) f - function() NULL formals(f) - list(b=1, c=2) f function (b = 1) 2 formals(f) - list(b=1, c=2)