<div dir="ltr">The best you can do is to get the pointer to the function (not sure if that does what you are hoping for):<div><br></div><div><span style="color:rgb(80,0,80);font-size:12.8px">func <- Rcpp::cppFunction("int foo() { return 1; }")</span><br></div><div><br></div><div><div>> body(func)</div><div>.Primitive(".Call")(<pointer: 0x103bf0f40>)</div></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 28, 2017 at 8:00 PM, Iñaki Úcar <span dir="ltr"><<a href="mailto:i.ucar86@gmail.com" target="_blank">i.ucar86@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">2017-07-29 0:29 GMT+02:00 Dirk Eddelbuettel <<a href="mailto:edd@debian.org">edd@debian.org</a>>:<br>
><br>
> On 28 July 2017 at 19:14, Iñaki Úcar wrote:<br>
> | Hi all,<br>
> |<br>
> | I found this interesting thread by Davor Cubranic in which Romain came<br>
> | up with a solution for calling a C routine from the 'stats' package:<br>
> | <a href="http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2010-June/000753.html" rel="noreferrer" target="_blank">http://lists.r-forge.r-<wbr>project.org/pipermail/rcpp-<wbr>devel/2010-June/000753.html</a><br>
> |<br>
> | In a nutshell, I would like to do the same, but with a user-provided<br>
> | function compiled with Rcpp::cppfunction. Namely,<br>
> |<br>
> | 1) get the externalptr<br>
> | 2) get the DL_FUNC with R_ExternalPtrAddrFn<br>
> | 3) use it<br>
> |<br>
> | Thanks to Romain, 2) and 3) are straightforward. The problem is the<br>
> | first step. I saw that, if I compile a function like this<br>
> |<br>
> | > Rcpp::cppFunction("int foo() { return 1; }")<br>
> |<br>
> | then I can obtain the externalptr with<br>
> |<br>
> | > getNativeSymbolInfo("<wbr>sourceCpp_ID_foo")<br>
> |<br>
> | but the problem is that you have to figure out this ID. Is there a<br>
> | general way to obtain the name of the native symbol that Rcpp<br>
> | produces? (Also I suppose that the initial "sourceCpp_" part could<br>
> | change in the future).<br>
><br>
> I recall that clever trick.<br>
><br>
> The problem is that R Core really does not want us to access such unexported<br>
> access points.<br>
<br>
</span>R Core may or may not want us to do 2) and 3), AKA the tricky part.<br>
But all I'm asking is how to get the externalptr from a cppFunction,<br>
which is just another (*kinda*) valid R data type. ;) R core provides<br>
getNativeSymbolInfo and Rcpp sets up the symbol name: it should be<br>
easy for Rcpp to expose the externalptr (if it's not already the<br>
case).<br>
<span class="HOEnZb"><font color="#888888"><br>
Iñaki<br>
</font></span><div class="HOEnZb"><div class="h5">______________________________<wbr>_________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-<wbr>project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" rel="noreferrer" target="_blank">https://lists.r-forge.r-<wbr>project.org/cgi-bin/mailman/<wbr>listinfo/rcpp-devel</a></div></div></blockquote></div><br></div>