Re: [Rd] Fast way to call an R function from C++?

2019-06-19 Thread Iñaki Ucar
On Wed, 19 Jun 2019 at 07:42, King Jiefei wrote: > > Hello Kevin and Iñaki, > > Thanks for your quick responses. I sincerely appreciate them! I can see how > complicated it is to interact with R in C. Iñaki's suggestion is very > helpful, I saw there is a lot of performance gain by turning the

Re: [Rd] Fast way to call an R function from C++?

2019-06-18 Thread King Jiefei
Hello Kevin and Iñaki, Thanks for your quick responses. I sincerely appreciate them! I can see how complicated it is to interact with R in C. Iñaki's suggestion is very helpful, I saw there is a lot of performance gain by turning the flag on, but sadly the best performance it can offer still

Re: [Rd] Fast way to call an R function from C++?

2019-06-18 Thread Iñaki Ucar
On Tue, 18 Jun 2019 at 19:41, King Jiefei wrote: > > [...] > > It is clear to see that calling an R function in R is the fast one, it is > about 5X faster than ` R_forceAndCall ` and ` Rf_eval`. the latter two > functions have a similar performance and using Rcpp is the worst one. Is it >

Re: [Rd] Fast way to call an R function from C++?

2019-06-18 Thread Iñaki Ucar
For reference, your benchmark using UNWIND_PROTECT: > system.time(test(testFunc, evn$x)) user system elapsed 0.331 0.000 0.331 > system.time(test(C_test1, testFunc, evn$x)) user system elapsed 2.029 0.000 2.036 > system.time(test(C_test2, expr, evn)) user system elapsed

Re: [Rd] Fast way to call an R function from C++?

2019-06-18 Thread Kevin Ushey
Hi Jiefei, Calling into R from C++ code is more complicated than one might think. Please see Tomas Kalibera's post here: https://developer.r-project.org/Blog/public/2019/03/28/use-of-c---in-packages/index.html The Rcpp Function class is more expensive than a regular Rf_eval() because it tries to

[Rd] Fast way to call an R function from C++?

2019-06-18 Thread King Jiefei
Hi, I'm looking for a most efficient way to call an R function from C++ in a package. I know there are two functions (`R_forceAndCall` and `Rf_eval`) that can do the "call" part, but both are slow compared to calling the same function in R. I also try to use Rcpp and it is the worse one. Here is