[Rcpp-devel] generalizing make_list

Romain Francois romain at r-enthusiasts.com
Thu Mar 18 13:16:16 CET 2010


Le 18/03/10 12:55, Dirk Eddelbuettel a écrit :
>
> Hi Romain,
>
> On 18 March 2010 at 12:22, Romain Francois wrote:
> | Hello,
> |
> | I am very happy about the make_list templates, but it only handles
> | lists, and the next best thing would be having something that would
> | handle all sorts of vectors.
>
> My first question would be "Why exactly?"  We have a very clear use case for
> lists as we need to ship results back to the calling R process.  But why do
> we need that ?

named vectors are as common in R as named lists.

RcppArmadillo has an example of creating a named integer vector:

IntegerVector version(3);
version = av.major, av.minor, av.patch ;
CharacterVector names(3);
names = "major", "minor", "patch" ;
version.names() = names ;

> | With some imagination, I think we can achieve this, but I was wondering
> | what the interface should be like. I was thinking maybe making it static
> | member function templates of Vector<>, so that we would do for example:
> |
> | NumericVector x = NumericVector::create(
> | 	_["x"] = 2.0,
> | 	_["y"] = 1.0
> | ) ;
>
> Again, why?  I would guess that the corpus of existing C++ code calling its
> elements by name is pretty limited.  So why do we need or want to create
> named vectors at the c++ level?  For returning to R, sure, but can't that be
> had with less firepower?

For example ?

> Don't want to be difficult here but maybe our time is spend more fruitfully
> one layer up (eg returning to RProtoBuf)

Sure. be my guest. why don't you start a discussion on what features of 
RProtoBuf you are talking about and how you are going to handle them ...

> than the endlessly add features
> here.  Rcpp is pretty good as it stands, why not let it rest a little?
>
> Dirk
>
> | I am more interested about a discussion about what should it be instead
> | of create than the usual conversation about _. There will be an
> | alternative to _, although it might involve more syntax, e.g.
> |
> | NumericVector x = NumericVector::create(
> | 	named<REALSXP>("x") = 2.0,
> | 	named<REALSXP>("y") = 1.0
> | ) ;
> |
> | or :
> |
> | NumericVector x = NumericVector::create(
> | 	NumericVector::named("x") = 2.0,
> | 	NumericVector::named("y") = 1.0
> | ) ;
> |
> | etc ...
> |
> | Ideas ?



-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/OIXN : raster images and RImageJ
|- http://tr.im/OcQe : Rcpp 0.7.7
`- http://tr.im/O1wO : highlight 0.1-5



More information about the Rcpp-devel mailing list