[Rcpp-devel] Resolving NativeSymbolInfos from Rcpp (revisited)

Iñaki Úcar i.ucar86 at gmail.com
Sat Jul 29 15:00:41 CEST 2017


2017-07-29 13:58 GMT+02:00 JJ Allaire <jj.allaire at gmail.com>:
> The best you can do is to get the pointer to the function (not sure if that
> does what you are hoping for):
>
> func <- Rcpp::cppFunction("int foo() { return 1; }")
>
>> body(func)
> .Primitive(".Call")(<pointer: 0x103bf0f40>)

I don't think so. Let me explain the motivation behind my question;
this way you can judge whether it's worth it.

With our simulator, simmer, we are able to generate arrivals, entities
that execute a given set of activities. One of these activities could
be, let's say, a delay. A user can provide this delay as a fixed
parameter to the C++ core, but also as a function that returns a
value, giving them a lot of flexibility to implement the simulation
model. As a trade-off, calling an R function from C++ is slow.

Now, what if the user needs flexibility *and* speed and so decides to
pass a cppFunction instead? This is perfectly valid and works like a
charm. In fact, this speeds up things a lot, especially if the
function was performing some heavy processing. *However*, it means
that we still have C++ calling R calling C++.

This is why I say, what if I can detect that situation and completely
get rid of that thin R layer? What if I can extract the pointer and
call C++ directly from my C++ core? I would expect an impressive
performance improvement.

Iñaki


More information about the Rcpp-devel mailing list