[R] eval(parse(...)) only once in a function

Christof Kluß ckluss at email.uni-kiel.de
Tue Sep 18 12:42:24 CEST 2012


Hi Thomas

thx, already the e <- parse(text="df$str==12")[[1]] is nice. So I have
not to call parse in my function! (The function is called very often, so
it makes the program much faster.)

And eval(bquote(function(df) b<-.(e))) is great! That's exactly what I
was looking for.


Christof


Am 17-09-2012 22:52, schrieb Thomas Lumley:
> On Mon, Sep 17, 2012 at 6:27 PM, Christof Kluß <ckluss at email.uni-kiel.de> wrote:
>> but for performance "eval(parse(a))" should not be evaluated at each
>> function call, but should work as
>> 
> You can do it with bquote()
> 
>> e<-parse(text="df$str==12")[[1]]
>> e
> df$str == 12
>> bquote(function(df) b<-.(e))
> function(df) b <- df$str == 12

>> eval(bquote(function(df) b<-.(e)))
> function (df)
> b <- df$str == 12
> 
> This saves more time than I expected, about 100ms per evaluation on my
> computer.




More information about the R-help mailing list