Nick
Nick

Reputation: 10499

Rcpp get element by name - $ operator

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?

Upvotes: 5

Views: 192

Answers (1)

Dirk is no longer here
Dirk is no longer here

Reputation: 368399

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.

Upvotes: 5

Related Questions