[Rcpp-devel] Vector<>::create

Dirk Eddelbuettel edd at debian.org
Fri Mar 19 15:03:56 CET 2010


On 19 March 2010 at 14:01, Romain Francois wrote:
| I've commited Vector<>::create methods to support creation of any kind 
| of vectors with named or unnamed objects. examples:
| 
| // creating an unamed integer vector
| IntegerVector::create( 10, 20 ) ;
| 
| // creating a named character vector
| CharacterVector::create( _["foo"] = "bar", _["bar"] = "foo" ) ;
| 
| // creating a named list
| List::create( _["foo"] = 10, _["bar"] = true ) ;
| 
| The syntax :
| 
| _[.] = .
| 
| can be replaced by this for people who don't like _ :
| 
| Argument( . ) = .
| 
| so for example :
| 
| List::create( Argument("foo") = 10, Argument("bar") = true ) ;

Really nice work!
 
| I could not use Named as it is now because it wraps the object too early 
| and so would only work for lists (which contains SEXP) and would not 
| work for e.g. integer vectors.
| 
| Here the rhs of Argument::operator= is kept as a reference until it is 
| effectively stored in the object, so Argument::operator= makes an object 
| of the template class traits::named_object which create knows how to 
| deal with, but the key is that named_object does not wrap but only 
| contains reference.
| 
| The new question is : should "Argument" be called something else ? 
| Should I rework all others clients of Named so that they use Argument 
| instead (in that case I would then call it Named).

Tricky one. We'd be altering a published interfaces which is bad, but then
the paint is barely on these interfaces. I guess this can be argued either
way.  What do you think?   What do other lurkers thing?

Dirk

-- 
  Registration is open for the 2nd International conference R / Finance 2010
  See http://www.RinFinance.com for details, and see you in Chicago in April!


More information about the Rcpp-devel mailing list