[Rcpp-devel] multiple function when using Inline
Darren Cook
darren at dcook.org
Thu Oct 20 13:13:43 CEST 2011
> I'm not too clear on how to include the other c++ functions. Is
> there a good example of this somewhere?
As Romain said, you abuse the includes argument (which is intended for
specifying #includes, etc. but can be anything) by putting the full
function in there.
Here is one way to calculate pi-squared:
----------------
library('inline')
header="
//Functions only visible by C++ code go here
double square_me(double x){
return x*x;
}
"
src="
//The callable-from-R function *body* goes here
double v=square_me(3.14);
return Rcpp::wrap(v);
";
fun=cxxfunction(signature(),src,plugin="Rcpp",includes=header)
print(fun())
----------------
If you don't see what is happening, add verbose=TRUE to the cxxfunction
call, and take a look at the source code that has been constructed.
Darren
--
Darren Cook, Software Researcher/Developer
http://dcook.org/work/ (About me and my work)
http://dcook.org/blogs.html (My blogs and articles)
More information about the Rcpp-devel
mailing list