[Rcpp-devel] binding, combining vectors

Romain Francois romain at r-enthusiasts.com
Thu Dec 13 10:01:41 CET 2012


I'd like to add a functionality to "bind" vectors of the same type (well 
sugar expressions really, but let's say it is vectors for the sake of 
this email).

So essentially I'd like something similar to what "c" does in R :

 > c( letters, letters )
  [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" 
"q" "r" "s"
[20] "t" "u" "v" "w" "x" "y" "z" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" 
"k" "l"
[39] "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z"

I don't want to call it "c", and I'd like suggestions : combine, bind ?

The idea is to avoid writing code like this:

CharacterVector x, y ;
CharacterVector z( x.size() + y.size() ) ;
int i=0;
for( ; i<x.size(); i++) z[i] = x[i] ;
for( int j=0; j<y.size(); i++, j++) z[i] = y[j] ;

I know it is not a big deal for people to write this code, but for 
example this does not handle the names of the elements, ... and 
internally I can use more efficient code


Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30

R Graph Gallery: http://gallery.r-enthusiasts.com

blog:            http://romainfrancois.blog.free.fr
|- http://bit.ly/RE6sYH : OOP with Rcpp modules
`- http://bit.ly/Thw7IK : Rcpp modules more flexible

More information about the Rcpp-devel mailing list