[Rcpp-devel] self documentation for exposed methods

Romain Francois romain at r-enthusiasts.com
Mon Nov 22 13:15:17 CET 2010


Hello,

I've commited some code yesterday and this morning that implements self 
documentation of C++ exposed methods.

This is based on the $help feature of reference classes. See the section 
"Writing Reference Methods" in ?ReferenceClasses

Now .method allows you to include documentation of a method, as shown in 
the example below:


require( Rcpp )
require( inline )
inc <- '

class Simple {
public:
     Simple( ) : d_x(10.0){} ;
     Simple( double x ) : d_x(x){} ;

     const double& x(){ return d_x ;}

     void move( double x ){ d_x += x ; }

private:
     double d_x ;
		
} ;

double bla( Simple* data ){ return 3; }

RCPP_MODULE(mod){

	class_<Simple>( "Simple" )

	    .constructor()
	    .constructor<double>( )
	
		.property( "x" , &Simple::x )
		.method( "move", &Simple::move, "some documentation for the move 
method" )
		.method( "bla", &bla, "bla bla" )
		;
		

}
'

fx <- cxxfunction( , '', includes = inc, plugin = "Rcpp" )
mod <- Module( "mod", getDynLib( fx ) )
Simple <- mod$Simple




 > Simple$help( "bla" )
Call: $bla(...)

double bla()
	docstring : bla bla

 > Simple$help( "move" )
Call: $move(...)

void move(double)
	docstring : some documentation for the move method


The validator described in this thread 
http://article.gmane.org/gmane.comp.lang.r.rcpp/977 is still available, 
but the validator function appears after the docstring.

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