Message-ID: <7E8037094A0C2146AA3E6F94DAE621C393218CC6@AD-EXCHMBX2-1.aau.dk>
Date: 2014-01-21T22:02:56Z
From: Søren Højsgaard
Subject: [Rcpp-devel] Rcpp version of c( )
Dear all,
I have made the following primitive "concatenate" function, because I couldn't find one in Rcpp:
template <const int RTYPE>
Vector<RTYPE> do_conc_(Vector<RTYPE> x, Vector<RTYPE> y){
int nx=x.size(), n=x.size()+y.size(),i,j;
Vector<RTYPE> out=no_init(n);
for (i=0; i<nx; ++i){ out[ i ] = x[ i ];}
for (j=i, i=0; j<n; ++j, ++i){ out[ j ] = y[i] ;}
return out;
}
// [[Rcpp::export]]
SEXP conc( SEXP& XX_, SEXP& YY_){
int type = TYPEOF(XX_) ;
switch( type ){
case INTSXP : return do_conc_<INTSXP> ( XX_, YY_ ) ;
case REALSXP : return do_conc_<REALSXP>( XX_, YY_ ) ;
case STRSXP : return do_conc_<STRSXP> ( XX_, YY_ ) ;
case VECSXP : return do_conc_<VECSXP> ( XX_, YY_ ) ;
}
return R_NilValue ;
}
As you can see it assumes that the two inputs XX_ and YY_ are of the same type, and it fails to copy names to the output. If I have missed any such functionality in Rcpp then I would be happy to know...
Cheers
S?ren