I would like to access a named list element by name in Rcpp
In R
> b = list(bgroups=c(1,1,1,1,1,0,0,0,0,0))
> b$bgroups
[1] 1 1 1 1 1 0 0 0 0 0
Then when trying to access this in Rcpp I have tried:
cppFunction(
"
void f(List & b){
std::vector<int> c(10) = as<std::vector<int>> b['bgroups'];
}
"
)
...
NumericVector groupings = b['bgroups'];
...
NumericVector groupings(10) = b(4);
But to no avail.
I've reviewed Dirk's many helpful answers, but have not been able to make the connection https://github.com/eddelbuettel/rcppexamples/blob/master/src/ListExample.cpp