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

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


2017-07-29 0:29 GMT+02:00 Dirk Eddelbuettel <edd at debian.org>:
>
> On 28 July 2017 at 19:14, Iñaki Úcar wrote:
> | Hi all,
> |
> | I found this interesting thread by Davor Cubranic in which Romain came
> | up with a solution for calling a C routine from the 'stats' package:
> | http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2010-June/000753.html
> |
> | In a nutshell, I would like to do the same, but with a user-provided
> | function compiled with Rcpp::cppfunction. Namely,
> |
> | 1) get the externalptr
> | 2) get the DL_FUNC with R_ExternalPtrAddrFn
> | 3) use it
> |
> | Thanks to Romain, 2) and 3) are straightforward. The problem is the
> | first step. I saw that, if I compile a function like this
> |
> | > Rcpp::cppFunction("int foo() { return 1; }")
> |
> | then I can obtain the externalptr with
> |
> | > getNativeSymbolInfo("sourceCpp_ID_foo")
> |
> | but the problem is that you have to figure out this ID. Is there a
> | general way to obtain the name of the native symbol that Rcpp
> | produces? (Also I suppose that the initial "sourceCpp_" part could
> | change in the future).
>
> I recall that clever trick.
>
> The problem is that R Core really does not want us to access such unexported
> access points.

R Core may or may not want us to do 2) and 3), AKA the tricky part.
But all I'm asking is how to get the externalptr from a cppFunction,
which is just another (*kinda*) valid R data type. ;) R core provides
getNativeSymbolInfo and Rcpp sets up the symbol name: it should be
easy for Rcpp to expose the externalptr (if it's not already the
case).

Iñaki


More information about the Rcpp-devel mailing list