[Rcpp-devel] formals( C++Function )

Romain Francois romain at r-enthusiasts.com
Wed Nov 24 19:58:06 CET 2010


Hello,

I've added some code that allows one to set the formals of a C++ 
function exposed through a module.

For 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, "bla bla nla" ) ;
}
', plugin = "Rcpp" )

mod <- Module( "mod", getDynLib(fx) )
norm <- mod$norm
formals(norm) <- alist( x=0, y=0)

 > norm()
[1] 0
 > norm( x = 3, y = 4 )
[1] 5

I might add hooks later so that one can declare the formals directly as 
part of the ".function" call, but I'm not sure how to.

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