Skip to content
Prev 7025 / 10988 Next

[Rcpp-devel] Rcpp version of c( )

Hi Kevin,

Thanks for your reply. I was only introduced to C++11 last week (my fault!); it seems that everybodys life becomes much easier once R-packages can be made with that...

I think many Rcpp-friends would welcome a version of c( ). One view is of course that it should be as general as R's c( )-function. A more pragmatic view is a version of c() that could concatenate (a) two lists and (b) two vectors (where each can be integers, doubles, characters and complex, independently of each other). I guess that would satisfy 90+% of the needs for a c( ) function in an Rcpp setting...  

Best regards
S?ren


-----Original Message-----
From: Kevin Ushey [mailto:kevinushey at gmail.com] 
Sent: 22. januar 2014 01:10
To: S?ren H?jsgaard
Cc: rcpp-devel at lists.r-forge.r-project.org (rcpp-devel at r-forge.wu-wien.ac.at)
Subject: Re: [Rcpp-devel] Rcpp version of c( )

Hi S?ren,

I like the idea. Currently there is nothing like that in Rcpp. It could be made more flexible if we:

1. Accept a generic set of vectors that could be appropriately casted as needed, 2. Cast these vectors to the appropriate type if necessary, 3. Fill an output vector with the elements of these vectors.

Of course, we would like to be able to accept primitives as well so that e.g. c(x, 1, y) works so something a bit more designed would be nice.

There should be a flexible way to implement this using variadic templates, so that e.g.

template <typename T, typename... Args>
T c( Args... args ) {
    ...do the concatenation...
}

Of course, this requires C++11 so it might not fit until R 3.1.0 is out with its C++11 support, but it could be a natural fit in Rcpp11.
Adding the generic version in Rcpp would require code bloat unfortunately.

-Kevin
On Tue, Jan 21, 2014 at 2:02 PM, S?ren H?jsgaard <sorenh at math.aau.dk> wrote: