Re: [Rcpp-devel] Dynamic Wrapping and Recursion with Rcpp - using an R function?

2013-07-26 Thread Tal Galili
Hi Kevin, As to the "fu" function, I didn't return "node" since I thought the change was on the mutable object. But from your (very detailed, thank you!) answer, I am learning that my hope for a general way of doing what I wanted is not feasible. Again, thank you for the response - it was very in

Re: [Rcpp-devel] Dynamic Wrapping and Recursion with Rcpp - using an R function?

2013-07-26 Thread Kevin Ushey
Hi Tal, A couple points: 1) Your R function `fu` doesn't specify a return. In addition, calling an R function in C++ code is still going to fall into the same pitfalls of calling it directly in R -- you're going to make a copy, and going to have to reassign the copy. You can cheat by using `<<-`

Re: [Rcpp-devel] Dynamic Wrapping and Recursion with Rcpp - using an R function?

2013-07-26 Thread Krzysztof Sakrejda
Make the wrapper a reference class which has a field for the data. When the wrapper is initialized, pass the data as an argument and it will be copied when the initialize method runs. Works in my project... or am I missing something here? Krzysztof On Fri, Jul 26, 2013 at 4:58 PM, Tal Galili wro

Re: [Rcpp-devel] Dynamic Wrapping and Recursion with Rcpp - using an R function?

2013-07-26 Thread Tal Galili
Hi Hadley, Regarding the cloning of the object in C++: since I will want to use the function recursively, I will either have the cloning in the wrapper R function. And if I discover that is not possible (I haven't tried it yet), my next thought was to split the work into two functions, in one ther

Re: [Rcpp-devel] Dynamic Wrapping and Recursion with Rcpp - using an R function?

2013-07-26 Thread Hadley Wickham
> I understand your point, and am not sure how to proceed without it. Just make sure you clone the initial list once, or use another C++ data structure (e.g. std::vector) that can grow efficiently. Alternatively, you could create your own alternative to as.dendrogram that doesn't create a hierarc

Re: [Rcpp-devel] Dynamic Wrapping and Recursion with Rcpp - using an R function?

2013-07-26 Thread Tal Galili
Hi Hadley, Thank you for your prompt reply! I understand your point, and am not sure how to proceed without it. *Motivation*: I'm currently working on my dendextend package (link to github), and one of the biggest bottlenecks in working with dendrogram obj

Re: [Rcpp-devel] Dynamic Wrapping and Recursion with Rcpp - using an R function?

2013-07-26 Thread Hadley Wickham
> // 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!) Why do you want to do that? It's a generally a bad idea to modify R objects in place. Here's a simple example showing why C level

[Rcpp-devel] Dynamic Wrapping and Recursion with Rcpp - using an R function?

2013-07-26 Thread Tal Galili
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); r