I am looking to see if it is possible to have the same functionality as with()
in R in Rcpp for environments.
For example, in R, I can create an environment, add two variables, and use with()
to evaluate the expression using only variable names:
e <- new.env() e$x <- 1 e$y <- 2 with(e, x + y )
I can do something similar in Rcpp, but this requires indexing the environment:
f <- cxxfunction(signature(env="environment"), ' Environment e(env); double Res = (double)e["x"] + (double)e["y"]; return(wrap( Res )); ', plugin = "Rcpp" ) f(e)
Is it possible to evaluate an expression using only variable names in Rcpp? The reason I'm asking is because I want to write some kind of dynamic C ++ function where you can add expressions. For example, with some dummy code that doesn't work:
f <- cxxfunction(signature(env="environment"), sprintf(' Environment e(env); double Res; // Res = with(e, %s ); return(wrap( Res )); ','x + y'), plugin = "Rcpp" )
source share