[Rcpp-devel] exposing C++ function with formal argument specification
Romain Francois
romain at r-enthusiasts.com
Thu Nov 25 12:12:43 CET 2010
Hello,
I commited some code that allows one to declare formal argument
specification for an exposed C++ function. Here is an example:
require( inline )
require( Rcpp )
fx <- cxxfunction(, "", includes =
'using namespace Rcpp ;
double norm( double x, double y ){
return sqrt( x*x + y*y ) ;
}
RCPP_MODULE(mod){
function( "norm", &norm, List::create( _["x"] = 0.0, _["y"] = 0.0
), "bla bla nla" ) ;
}
', plugin = "Rcpp" )
mod <- Module( "mod", getDynLib(fx) )
norm <- mod$norm
> norm()
[1] 0
> norm( x = 3, y = 4 )
[1] 5
It is also possible to set a formal argument with no default value:
function( "norm", &norm, List::create( _["x"] = 0.0, _["y"] =
R_MissingArg ), "bla bla nla" ) ;
or even to use the ...
function( "norm", &norm, List::create( _["x"] = 0.0, _["..."] =
R_MissingArg ), "bla bla nla" ) ;
Romain
--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://bit.ly/9VOd3l : ZAT! 2010
|- http://bit.ly/c6DzuX : Impressionnism with R
`- http://bit.ly/czHPM7 : Rcpp Google tech talk on youtube
More information about the Rcpp-devel
mailing list