Thank you for your interest in Rcpp ! Romain and I usually assume that questions will be asked on the rcpp-devel list; you probably get some more suitable eyeballs.
Here you are trapped in single and double quotes. Switching these features makes it all work. I also reordered / rearranged / rewritten the code a bit while I played with it:
> f <- cxxfunction(signature(), + body=' Environment e = Environment::global_env(); + std::vector<double> vx = e["x"]; + return wrap(vx); ', + plugin="Rcpp") > x <- 3:6 > f() [1] 3 4 5 6 >
Edit: what it's worth is the same thing, but transferring the environment down. This is what I played with the first and which I somehow like better
f <- cxxfunction(signature(env="environment"), body=' Environment e(env); std::vector<double> vx = e["x"]; return wrap(vx); ', plugin="Rcpp") env <- new.env() env[["x"]] <- 1:4 f(env)
source share