title: using C function from other package in Rcpp
body: <p>I'm trying to call a C routine from the cubature package in a c++ function to perform multidimensional integration. </p>
  
  <p>The basic R example I'm trying to reproduce is</p>
  
  <pre><code>library(cubature)
  integrand &lt;- function(x) sin(x)
  adaptIntegrate(integrand, 0, pi)
  </code></pre>
  
  <p>I could just call this R function from Rcpp following <a href="http://gallery.rcpp.org/articles/r-function-from-c++/">this recipe from the gallery</a>, but there would be some performance penalty in switching back and forth from c/c++ to R. It seems more sensible to directly call the C function from C++.</p>
  
  <p>The C routine <code>adapt_integrate</code> is exported from <code>cubature</code> with</p>
  
  <pre><code> // R_RegisterCCallable("cubature", "adapt_integrate", (DL_FUNC) adapt_integrate);
  </code></pre>
  
  <p>I don't understand how to call it from c++, however. Here's my lame attempt,</p>
  
  <pre><code>sourceCpp(code = '
  #include &lt;Rcpp.h&gt;
  using namespace Rcpp;
  
  // [[Rcpp::export]]
  double integrand(double x){
   return(sin(x));
  }
  
  // [[Rcpp::depends(cubature)]]
  // [[Rcpp::export]]
  Rcpp::List integratecpp(double llim, double ulim)
  {
    Rcpp::Function p_cubature = R_GetCCallable("cubature", "adapt_integrate");
  
    Rcpp::List result = p_cubature(integrand, llim, ulim);
    return(result);
  }
  '
  )
  
  integratecpp(0, pi)
  </code></pre>
  
  <p>This fails to compile; clearly I'm doing something very silly and missing some important steps to convert the output of <code>R_GetCCallable</code> into an <code>Rcpp::Function</code> (or call it directly?). I've read several related posts dealing with function pointers, but haven't seen an example using an external C function.</p>