Skip to content
Back to formatted view

Raw Message

Message-ID: <FE33AE5A-77C7-4324-8568-DDB533863575@comcast.net>
Date: 2012-09-17T07:36:07Z
From: David Winsemius
Subject: eval(parse(...)) only once in a function
In-Reply-To: <k36fse$9o9$1@ger.gmane.org>

On Sep 16, 2012, at 11:27 PM, Christof Klu? wrote:

> Hi
> 
> I would like to have something like
> 
> str <- "df$JT == 12"
> 
> fun <- function(df) {
> 
>  b <- eval(parse(str))
> 
>  return(b)
> }
> 

What are you trying to do?

str <- quote(df$JT == 12)

> but for performance "eval(parse(a))" should not be evaluated at each
> function call, but should work as
> 
> fun <- function(df) {
> 
>  b <- df$JT == 12
> 
>  return(b)
> }
> 
> Do you have an idea how I can implement this?

Implement what?  And what issues regarding "performance" are relevant? What does it mean to "not evaluate at each function call"?

str <- quote(df$JT == 12)
fun <- function(df) {
    b<-eval(str)
    return(b)
   }

df3 <- data.frame(JT=12)
fun(df3)
#[1] TRUE

-- 



David Winsemius, MD
Alameda, CA, USA