[Rcpp-devel] Resolving NativeSymbolInfos from Rcpp
Dirk Eddelbuettel
edd at debian.org
Wed Jun 9 21:03:04 CEST 2010
Hi all,
That's a great question by Davor. Like many other people, I am also a fan of
loess (for the concrete example). But ...
On 9 June 2010 at 07:46, Romain Francois wrote:
| Le 09/06/10 07:14, Romain Francois a écrit :
| > Le 09/06/10 03:04, Davor Cubranic a écrit :
| >> There are some C routines in the 'stats' package that I would like to
| >> call directly from my Rcpp-based package, e.g., loess_raw. However,
| >> 'stats' only exposes them to R callers, not C or C++. (I.e., it does
| >> not use R_RegisterCCallable, but they are among R_CMethodDef's passed
| >> in R_registerRoutines.)
... at a fundamental level, I am not yet sure that 'poking through' an api
that R Core has sealed is the right idea.
My hunch is that I would just take the code to loess_raw and stick it into a
small utility package so that one could feed it data using Rcpp.
| After some more coffee, I came up with this:
|
| require( Rcpp )
| require( inline )
|
| # borrowed from R private headers
| # not part of R API, but does not change all that much
| include <- '
|
| typedef union {void *p; DL_FUNC fn;} fn_ptr;
|
| DL_FUNC R_ExternalPtrAddrFn(SEXP s){
| fn_ptr tmp;
| tmp.p = EXTPTR_PTR(s);
| return tmp.fn;
| }
|
| '
|
| code <- '
| // grab loess_raw
| DL_FUNC loess_raw = R_ExternalPtrAddrFn( xp ) ;
| Rprintf( "loess_raw : <%p>\\n", loess_raw ) ;
|
| // call it
| // (*loess_raw)( ... )
|
| return R_NilValue ;
| '
|
| fx <- cxxfunction( signature( xp = "externalptr" ),
| code, include = include, plugin = "Rcpp" )
| fx( getNativeSymbolInfo( "loess_raw" )$address )
|
|
| Please expand the part that is actually suppose to call loess_raw and
| let us know if something useful happens.
|
| It might be worth formalize that sort of things in a nice Rcpp
| abstraction. For example, make a Rcpp::DynamicLibrary class with member
| functions to pull these things conveniently.
That is certainly cool stuff just like Matt's recent blog (via R Bloggers)
posts that did similar stuff. I just haven't convinced myself that we should
really advertise usage like that.
Thoughts?
--
Regards, Dirk
More information about the Rcpp-devel
mailing list