Hello all, I would like to write an Rcpp function that will get an R object, an R function, and will use the function on the object through Rcpp. For example:
library(Rcpp) cppFunction('NumericVector runRfuncSum(NumericVector x, Function fu) { NumericVector fu_x = fu(x); return fu_x; }') runRfuncSum(c(1:4), sum) However, following the example given here: http://gallery.rcpp.org/articles/rcpp-wrap-and-recurse/ I would like this function to get an R List (specifically a dendrogram), and will recursively go through all of the dendrogram nodes and apply the function. I can't seem to get it to work. For example: cppFunction(' List dendrapply_Cpp_fun(List x, Function FUN) { // note: The FUN will change the object x itself // hence - it must be clear to use an object we wish to change (it will NOT be copied!) for( List::iterator it = x.begin(); it != x.end(); ++it ) { *it = FUN(*it); *it = dendrapply_Cpp_fun(*it, FUN); } return x; }') fu <- function(node) { attr(node, "height") = attr(node, "height")+1 } dend <- as.dendrogram(hclust(dist(USArrests[1:3,]), "ave")) dendrapply_Cpp_fun(dend, fu) Any suggestion as to why this is not working? Thanks! ----------------Contact Details:------------------------------------------------------- Contact me: tal.gal...@gmail.com | Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) ----------------------------------------------------------------------------------------------
_______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel