[Rcpp-devel] GenericVector looks more like std::vector
Romain Francois
romain at r-enthusiasts.com
Wed Feb 10 13:10:42 CET 2010
Hi,
I've added the following methods to SEXP_Vector (which is the template
that generates GenericVector (aka List) and ExpressionVector so that
they look more like std::vector :
push_back
push_front
insert
erase
Methods that add new things use the implicit wrap idiom : they take a
templated parameter as input, wrap it up into a SEXP using wrap. They
also take care of names using the Named class as in e.g Language.
erase has a single element form to remove a single element and a range
based form erase( iterator first, iterator last ) to remove all elements
from first to last.
All these functions actually copy the internal SEXP, as R offers no way
to do otherwise.
As usual, examples included in the unit tests. Here is one:
funx <- cfunction( signature(x = "list"),
'
List list(x) ;
list.push_back( 10 ) ;
list.push_back( Named( "foo", "bar" ) ) ;
return list ;
', Rcpp = TRUE, includes = "using namespace Rcpp;" )
d <- list( x = 1:10, y = letters[1:10] )
res <- funx( d )
checkEquals( res,
list( x = 1:10, y = letters[1:10], 10L, foo = "bar" ),
msg = "List.push_back" )
Romain
--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/NrTG : Rcpp 0.7.5
|- http://tr.im/MPYc : RProtoBuf: protocol buffers for R
`- http://tr.im/KfKn : Rcpp 0.7.2
More information about the Rcpp-devel
mailing list