Here's a really bare-bones version. Not very pretty or complete, but it
does do the job. Could the 'unlist' part be converted to Rcpp?
THK
library(Rcpp)
code = '
SEXP test(List a)
{
int l = Rf_length(a[0]);
typedef std::vector<SEXP> svec;
std::vector<svec> x(l);
for (int i = 0; i != l; ++i)
for (int j = 0; j != a.size(); ++j)
{
List b = a[j];
x[i].push_back(b[i]);
}
return wrap(x);
}'
f = cppFunction(code = code)
res = lapply(f(list(list(1, 'a'), list(2, 'b'))), unlist)
On Sat, May 2, 2015 at 1:18 PM, Dirk Eddelbuettel <[email protected]> wrote:
>
> On 2 May 2015 at 10:49, William Dunlap wrote:
> | Since translation from R to Rcpp is "seamless" I will leave that to you.
>
> One problem is with the strongly typed nature of C++. Rearranging
> dynamicly
> growing objects can be done. I think I used Boost's variant type a few
> years. I am sure there are other possibilities. We should collect a few
> and
> compare. But in C++ please :)
>
> Dirk
>
> --
> http://dirk.eddelbuettel.com | @eddelbuettel | [email protected]
>
--
http://www.keittlab.org/
_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel