[Rcpp-devel] Accumulating results in an Rcpp::List
Dirk Eddelbuettel
edd at debian.org
Sun Jun 20 04:17:31 CEST 2010
On 19 June 2010 at 20:32, Douglas Bates wrote:
| I want to return a named list of results from a call using Rcpp but
| the components of the list are accumulated in stages. At the C++
| level i have a templated class that contains several data members that
| are themselves instances of classes.
|
| What I have been doing is defining methods for each of the subclasses
| that update the list and return it. The signatures look like
|
| Rcpp::List updateList(Rcpp::List&)
|
| This particular signature reflects my R background where I would might
| write something like
|
| ans <- updateList(comp3, updateList(comp2, updateList(comp1, list()))
|
| However, it occurs to me that it might be unnecessary to return the
| list in C++ because I am passing a reference to the list so updates
| will change the original argument.
|
| Is this a good idea and does it work as long as I pass by reference?
| (I'm still a little vague on the distinction between passing a
| reference and passing a classed object.)
Why not? I guess the real answer may be found via profiling,
Most uses I have made of this involved fixed sizes. But there are push_back
method so one could grow lists dynamically which I haven't tried. Another
option would be to have lists of lists which I haven't tried yet either.
--
Regards, Dirk
More information about the Rcpp-devel
mailing list