[R] Evaluate an expresion comming from string

. . xkziloj at gmail.com
Thu Sep 1 05:12:53 CEST 2011


Whats wrong here?

I was expecting 11 as the result...

Thanks in advance.

bench <- function(str,...) {
func <- function(x) x+10
  expr <- list(...)[1]
  str <- gsub("XXX",expr,str)
  x <- as.call(gsub("\"","",str))
  eval(x)
}
bench("func(XXX)", "1")



More information about the R-help mailing list