[Rcpp-devel] List of Lists to List of Vectors

Tim Keitt tkeitt at utexas.edu
Sun May 3 18:57:37 CEST 2015


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 <edd at debian.org> 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 | edd at debian.org
>



-- 
http://www.keittlab.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20150503/dc816249/attachment.html>


More information about the Rcpp-devel mailing list