[Rcpp-devel] Accumulating results in an Rcpp::List

Douglas Bates bates at stat.wisc.edu
Sun Jun 20 03:32:43 CEST 2010


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.)


More information about the Rcpp-devel mailing list