[Rcpp-devel] How to create list of list without known structure

Dirk Eddelbuettel edd at debian.org
Tue May 6 12:18:10 CEST 2014


Hi Florian,

On 6 May 2014 at 09:35, Florian Burkart wrote:
| Hi,
| 
| I have been creating lists of lists with
| 
| return Rcpp::List::create(Rcpp::Named("vec") = someVector,
|                           Rcpp::Named("lst") = someList,
|                           Rcpp::Named("vec2") = someOtherVector);

Yes, it is a very common idiom as lists are the R structure used for nesting
object with varying types or sizes.
 
| or to follow Romain:
| 
| using namespace Rcpp ;
| return List::create(
|    _["vec"]  = someVector,
|    _["lst"]  = someList,
|    _["vec2"] = someOtherVector
|  ) ;
| 
| But how do I convert the following into a list of lists?
| 
| std::vector<std::string> m_column_headers;
| std::vector<std::vector<OptDouble> > m_vectors_of_values;

You probably have to copy at some point.  You could also use Rcpp types as
the first (std::vector<std::string>) could be an Rcpp::CharacterVector (which
is a vector of strings, not single char); the second could be a
Rcpp::NumericMatrix.  There is some support for as<> and wrap() between
these, but there is no function doing magic of the 'here, just convert these
random two types I listed'.  It all depends.

Hope this helps, Dirk

-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com


More information about the Rcpp-devel mailing list