Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rcpp get element by name - $ operator

Tags:

c++

r

rcpp

In R I can write:

l <- list(a=0, b="10");

And get the value of the element of the list named b as follow:

x <– l$b

Is there a way to get the same result by using an Rcpp::List object?

like image 767
Nick Avatar asked Nov 04 '15 20:11

Nick


1 Answers

Of course, and there are plenty of examples. Just use

std::string x = l["b"];

where l is the Rcpp::List object which is assumed to have names.

like image 79
Dirk Eddelbuettel Avatar answered Sep 29 '22 14:09

Dirk Eddelbuettel