[Rcpp-devel] How to create list of list without known structure
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); 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::vectorstd::string m_column_headers; std::vectorstd::vectorOptDouble m_vectors_of_values; Thank you, Florian ___ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
Re: [Rcpp-devel] How to create list of list without known structure
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::vectorstd::string m_column_headers; | std::vectorstd::vectorOptDouble m_vectors_of_values; You probably have to copy at some point. You could also use Rcpp types as the first (std::vectorstd::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 | e...@debian.org | http://dirk.eddelbuettel.com ___ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
Re: [Rcpp-devel] How to create list of list without known structure
Le 6 mai 2014 à 09:35, Florian Burkart florian.burk...@gmail.com a écrit : 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); 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::vectorstd::string m_column_headers; std::vectorstd::vectorOptDouble m_vectors_of_values; You probably just need to know about .names() =, i.e. something like this should do: List values = wrap(m_vectors_of_values) ; values.names() = m_column_headers ; FWIW, in Rcpp11, you could use structure, e.g. : List values = structure( m_vectors_of_values, _[names] = m_column_headers ) ; Romain ___ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel