[Rcpp-devel] Help with accessing and manipulating List objects

Tal Galili tal.galili at gmail.com
Fri Aug 16 20:48:25 CEST 2013


Dear Dirk, Romain, Kevin, and others.

Since I am currently actively working on extending the dendrogram object in
R, I have a real interest in finding and solving some of the major
bottlenecks of dendrogram manipulation.
Thank you all for all of your help and suggestions thus far.

I took the liberty of starting a github repo for a new R package
"RcppDend", you can see it here:
https://github.com/talgalili/RcppDend

It currently contains the function for label extraction from dendrogram (a
mixture of the code Romain and Dirk wrote, with some minor modifications by
me).
The Rcpp code is here:
https://github.com/talgalili/RcppDend/blob/master/src/labels_dendrogram.cpp
And the R code (wrapping it a bit, and adding documentation), is here:
https://github.com/talgalili/RcppDend/blob/master/R/RcppDend.r

Currently, I can get the labels.dendrogram function to work when I'm
compiling it in a local session, but *the function fails to work when
loaded from this package*. If you have suggestions on how to fix it, I'd be
happy to read.

And in general, I welcome any code contributions/commits.

Best,
Tal






----------------Contact
Details:-------------------------------------------------------
Contact me: Tal.Galili at gmail.com |
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
----------------------------------------------------------------------------------------------



On Fri, Aug 16, 2013 at 9:04 PM, Kevin Ushey <kevinushey at gmail.com> wrote:

> Just a suggestion re: recursion with Rcpp, yet another nice way we can
> recurse is through using the sugar lapply:
>
> -----
>
> #include <Rcpp.h>
> using namespace Rcpp;
>
> // [[Rcpp::export]]
> RObject add_attr(RObject x_) {
>   RObject x = clone(x_);
>   if (is<List>(x)) {
>     x = wrap( lapply( as<List>(x), add_attr ) );
>   } else {
>     x.attr("type") = "Other";
>   }
>   return x;
> }
>
> /*** R
> add_attr( list(x=list(a=1, b=2, c=3), y=list( list( d=4 ) ) ) )
> */
>
> -----
>
> If we want to operate on specific elements as well, we can use is<T> and
> as<T> together, and then operate on objects as needed.
>
> It lets us avoid an explicit for loop, and 'feels' more like R.
>
> -Kevin
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130816/bc4097f0/attachment.html>


More information about the Rcpp-devel mailing list