I am trying to define a function using Rcpp for speedup. The situation is as follows:
The RcppXts package does just that for a bunch of functions from the well-known xts package.
Edit: Here is some code from xts.
First, xts::src/init.c does the registration via a dozen or so declarations like
R_RegisterCCallable("xts","do_is_ordered",(DL_FUNC) &do_is_ordered);
Second, xts::inst/include/xtsApi.h provides a header for client packages with eg
SEXP attribute_hidden xtsIsOrdered(SEXP x, SEXP increasing, SEXP strictly) {
static SEXP(*fun)(SEXP,SEXP,SEXP) = NULL;
fun = (SEXP(*)(SEXP,SEXP,SEXP)) R_GetCCallable("xts","do_is_ordered");
return fun(x, increasing, strictly);
}
Third, in a client package such as RcppXts we define this (using Rcpp Modules) as
function("xtsIsOrdered",
&xtsIsOrdered,
List::create(Named("x"),
Named("increasing") = true,
Named("strictly") = true),
"Tests whether object is (strictly) (increasing) ordered");
which exposes it to R. We could equally well call the C function xtsIsOrdered from C++ code.
I removed the incorrect earlier comment that functions have to conform to 'SEXP in, SEXP out'.