eval(parse(...)) only once in a function
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