Reputation: 239
I am getting started with the Rcpp framwork for intergrating C++ function with R.
The following integration works just fine:
cppFunction('
double normal_dens( double x )
{
const double SQRT2PI = 2.50662827463;
return( exp(-x*x/2.0)/SQRT2PI );
}
')
next I want to integrate:
cppFunction('
double test( double x ,double a)
{
return( a* normal_dens(x););
}
')
the internal cpp-compiler complains ( rightly-so ) that the function normal_dens is not known. What is the easiest way to do this?
many thx
Upvotes: 1
Views: 165
Reputation: 17642
Each of these cppFunction
calls create an independent shared library. They don't know about each other.
An easy alternative is to have all on the same file:
#include <Rcpp.h>
// [[Rcpp::export]]
double normal_dens( double x ) {
const double SQRT2PI = 2.50662827463;
return( exp(-x*x/2.0)/SQRT2PI );
}
// [[Rcpp::export]]
double test( double x ,double a){
return( a* normal_dens(x););
}
and then call sourceCpp
on this file. Then later, you'll want to learn how to make packages.
Upvotes: 3