[Rcpp-commits] r2833 - pkg/Rcpp/inst/doc/Rcpp-modules

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jan 5 02:29:02 CET 2011


Author: edd
Date: 2011-01-05 02:29:02 +0100 (Wed, 05 Jan 2011)
New Revision: 2833

Modified:
   pkg/Rcpp/inst/doc/Rcpp-modules/Rcpp-modules.Rnw
Log:
whitespace and indentation changes, no content edits


Modified: pkg/Rcpp/inst/doc/Rcpp-modules/Rcpp-modules.Rnw
===================================================================
--- pkg/Rcpp/inst/doc/Rcpp-modules/Rcpp-modules.Rnw	2011-01-04 19:14:52 UTC (rev 2832)
+++ pkg/Rcpp/inst/doc/Rcpp-modules/Rcpp-modules.Rnw	2011-01-05 01:29:02 UTC (rev 2833)
@@ -30,13 +30,13 @@
 \date{\pkg{Rcpp} version \Sexpr{prettyVersion} as of \Sexpr{prettyDate}}
 
 <<echo=FALSE>>=
-link <- function( f, package, text = f, root = "http://finzi.psych.upenn.edu/R/library/" ){
+link <- function( f, package, text = f, root = "http://finzi.psych.upenn.edu/R/library/" ) {
 	h <- if( missing(package) ) {
 		as.character( help( f ) )
 	} else {
 		as.character( help( f, package = paste( package, sep = "" ) ) )
 	}
-	if( ! length(h) ){
+	if( ! length(h) ) {
 		sprintf( "\\\\textbf{%s}", f )
 	} else {
 		rx <- "^.*/([^/]*?)/help/(.*?)$"
@@ -45,7 +45,7 @@
 		sprintf( "\\\\href{%s%s/html/%s.html}{\\\\texttt{%s}}", root, package, page, text )
 	}
 }
-linkS4class <- function( cl, package, text = cl, root = "http://finzi.psych.upenn.edu/R/library/" ){
+linkS4class <- function( cl, package, text = cl, root = "http://finzi.psych.upenn.edu/R/library/" ) {
 	link( sprintf("%s-class", cl), package, text, root )
 }
 @
@@ -90,8 +90,8 @@
 Consider the \texttt{norm} function below:
 
 <<lang=cpp>>=
-double norm( double x, double y ){
-	return sqrt( x*x + y*y ) ;
+double norm( double x, double y ) {
+    return sqrt( x*x + y*y );
 }
 @
 
@@ -101,13 +101,13 @@
 that does match the \texttt{.Call} requirements. \pkg{Rcpp} makes this easy.
 
 <<lang=cpp>>=
-using namespace Rcpp ;
-RcppExport SEXP norm_wrapper(SEXP x_, SEXP y_){
+using namespace Rcpp;
+RcppExport SEXP norm_wrapper(SEXP x_, SEXP y_) {
     // step 0: convert input to C++ types
-    double x = as<double>(x_), y = as<double>(y_) ;
+    double x = as<double>(x_), y = as<double>(y_);
 
     // step 1: call the underlying C++ function
-    double res = norm( x, y ) ;
+    double res = norm( x, y );
 
     // step 2: return the result as a SEXP
     return wrap( res );
@@ -135,15 +135,15 @@
 <<lang=cpp>>=
 class Uniform {
 public:
-    Uniform(double min_, double max_) : min(min_), max(max_){}
+    Uniform(double min_, double max_) : min(min_), max(max_) {}
 
-    NumericVector draw(int n){
-        RNGScope scope ;
-        return runif( n, min, max ) ;
+    NumericVector draw(int n) {
+        RNGScope scope;
+        return runif( n, min, max );
     }
 
 private:
-    double min, max ;
+    double min, max;
 };
 @
 
@@ -154,34 +154,34 @@
 with these two functions:
 
 <<lang=cpp>>=
-using namespace Rcpp ;
+using namespace Rcpp;
 
 /// create an external pointer to a Uniform object
-RcppExport SEXP Uniform__new(SEXP min_, SEXP max_){
+RcppExport SEXP Uniform__new(SEXP min_, SEXP max_) {
     // convert inputs to appropriate C++ types
-    double min = as<double>(min_), max = as<double>(max_) ;
+    double min = as<double>(min_), max = as<double>(max_);
 
     // create a pointer to an Uniform object and wrap it
     // as an external pointer
-    Rcpp::XPtr<Uniform> ptr( new Uniform( min, max ), true ) ;
+    Rcpp::XPtr<Uniform> ptr( new Uniform( min, max ), true );
 
     // return the external pointer to the R side
-    return ptr ;
+    return ptr;
 }
 
 /// invoke the draw method
 RcppExport SEXP Uniform__draw( SEXP xp, SEXP n_ ) {
-	// grab the object as a XPtr (smart pointer) to Uniform
-    Rcpp::XPtr<Uniform> ptr(xp) ;
+    // grab the object as a XPtr (smart pointer) to Uniform
+    Rcpp::XPtr<Uniform> ptr(xp);
 
     // convert the parameter to int
-    int n = as<int>(n_) ;
+    int n = as<int>(n_);
 
     // invoke the function
-    NumericVector res = ptr->draw( n ) ;
+    NumericVector res = ptr->draw( n );
 
     // return the result to R
-    return res ;
+    return res;
 }
 @
 
@@ -190,47 +190,47 @@
 
 <<echo=FALSE,results=hide>>=
 f1 <- cxxfunction( , "", includes = '
-using namespace Rcpp ;
+using namespace Rcpp;
 
 class Uniform {
 public:
-    Uniform(double min_, double max_) : min(min_), max(max_){}
+    Uniform(double min_, double max_) : min(min_), max(max_) {}
 
-    NumericVector draw(int n){
-        RNGScope scope ;
-        return runif( n, min, max ) ;
+    NumericVector draw(int n) {
+        RNGScope scope;
+        return runif( n, min, max );
     }
 
 private:
-    double min, max ;
+    double min, max;
 };
 
 /// create an external pointer to a Uniform object
-RcppExport SEXP Uniform__new(SEXP min_, SEXP max_){
+RcppExport SEXP Uniform__new(SEXP min_, SEXP max_) {
     // convert inputs to appropriate C++ types
-    double min = as<double>(min_), max = as<double>(max_) ;
+    double min = as<double>(min_), max = as<double>(max_);
 
     // create a pointer to an Uniform object and wrap it
     // as an external pointer
-    Rcpp::XPtr<Uniform> ptr( new Uniform( min, max ), true ) ;
+    Rcpp::XPtr<Uniform> ptr( new Uniform( min, max ), true );
 
     // return the external pointer to the R side
-    return ptr ;
+    return ptr;
 }
 
 /// invoke the draw method
 RcppExport SEXP Uniform__draw( SEXP xp, SEXP n_ ) {
-	// grab the object as a XPtr (smart pointer) to Uniform
-    Rcpp::XPtr<Uniform> ptr(xp) ;
+    // grab the object as a XPtr (smart pointer) to Uniform
+    Rcpp::XPtr<Uniform> ptr(xp);
 
     // convert the parameter to int
-    int n = as<int>(n_) ;
+    int n = as<int>(n_);
 
     // invoke the function
-    NumericVector res = ptr->draw( n ) ;
+    NumericVector res = ptr->draw( n );
 
     // return the result to R
-    return res ;
+    return res;
 }
 ', plugin = "Rcpp" )
 getDynLib( f1 )
@@ -240,16 +240,16 @@
 setClass( "Uniform", representation( pointer = "externalptr" ) )
 
 # helper
-Uniform_method <- function(name){
-	paste( "Uniform", name, sep = "__" )
+Uniform_method <- function(name) {
+    paste( "Uniform", name, sep = "__" )
 }
 
 # syntactic sugar to allow object$method( ... )
-setMethod( "$", "Uniform", function(x, name ){
-	function(...) .Call( Uniform_method(name) , x at pointer, ... )
+setMethod( "$", "Uniform", function(x, name ) {
+    function(...) .Call( Uniform_method(name) , x at pointer, ... )
 } )
 # syntactic sugar to allow new( "Uniform", ... )
-setMethod( "initialize", "Uniform", function(.Object, ...){
+setMethod( "initialize", "Uniform", function(.Object, ...) {
     .Object at pointer <- .Call( Uniform_method("new"), ... )
     .Object
 } )
@@ -286,14 +286,14 @@
 We can expose it to \proglang{R} :
 
 <<lang=cpp>>=
-using namespace Rcpp ;
+using namespace Rcpp;
 
-double norm( double x, double y ){
-	return sqrt( x*x + y*y ) ;
+double norm( double x, double y ) {
+    return sqrt( x*x + y*y );
 }
 
-RCPP_MODULE(mod){
-	function( "norm", &norm ) ;
+RCPP_MODULE(mod) {
+    function( "norm", &norm );
 }
 @
 
@@ -315,43 +315,43 @@
 many internal functions to \proglang{R}. For example, these 6 functions :
 
 <<lang=cpp>>=
-std::string hello(){
-	return "hello" ;
+std::string hello() {
+    return "hello";
 }
 
-int bar( int x){
-	return x*2 ;
+int bar( int x) {
+    return x*2;
 }
 
-double foo( int x, double y){
-	return x * y ;
+double foo( int x, double y) {
+    return x * y;
 }
 
-void bla( ){
-	Rprintf( "hello\\n" ) ;
+void bla( ) {
+    Rprintf( "hello\\n" );
 }
 
-void bla1( int x){
-	Rprintf( "hello (x = %d)\\n", x ) ;
+void bla1( int x) {
+    Rprintf( "hello (x = %d)\\n", x );
 }
 
-void bla2( int x, double y){
-	Rprintf( "hello (x = %d, y = %5.2f)\\n", x, y ) ;
+void bla2( int x, double y) {
+    Rprintf( "hello (x = %d, y = %5.2f)\\n", x, y );
 }
 @
 
 It can be exposed with the following minimal code:
 
 <<lang=cpp>>=
-RCPP_MODULE(yada){
-    using namespace Rcpp ;
+RCPP_MODULE(yada) {
+    using namespace Rcpp;
 
-    function( "hello" , &hello ) ;
-    function( "bar"   , &bar   ) ;
-    function( "foo"   , &foo   ) ;
-    function( "bla"   , &bla   ) ;
-    function( "bla1"  , &bla1   ) ;
-    function( "bla2"  , &bla2   ) ;
+    function( "hello" , &hello );
+    function( "bar"   , &bar   );
+    function( "foo"   , &foo   );
+    function( "bla"   , &bla   );
+    function( "bla1"  , &bla1   );
+    function( "bla2"  , &bla2   );
 }
 @
 
@@ -389,14 +389,14 @@
 to pass a short description of the function as the third parameter of \texttt{function}.
 
 <<lang=cpp>>=
-using namespace Rcpp ;
+using namespace Rcpp;
 
-double norm( double x, double y ){
-	return sqrt( x*x + y*y ) ;
+double norm( double x, double y ) {
+    return sqrt( x*x + y*y );
 }
 
-RCPP_MODULE(mod){
-	function( "norm", &norm, "Provides a simple vector norm" ) ;
+RCPP_MODULE(mod) {
+    function( "norm", &norm, "Provides a simple vector norm" );
 }
 @
 
@@ -405,14 +405,14 @@
 <<echo=FALSE>>=
 fx <- cxxfunction( , "", includes = '
 
-using namespace Rcpp ;
+using namespace Rcpp;
 
-double norm( double x, double y ){
-	return sqrt( x*x + y*y ) ;
+double norm( double x, double y ) {
+    return sqrt( x*x + y*y );
 }
 
-RCPP_MODULE(mod){
-	function( "norm", &norm, "Provides a simple vector norm" ) ;
+RCPP_MODULE(mod) {
+    function( "norm", &norm, "Provides a simple vector norm" );
 }
 ', plugin = "Rcpp" )
 mod <- Module( "mod", getDynLib( fx ) )
@@ -428,17 +428,17 @@
 a \texttt{Rcpp::List} after the function pointer.
 
 <<lang=cpp>>=
-using namespace Rcpp ;
+using namespace Rcpp;
 
-double norm( double x, double y ){
-        return sqrt( x*x + y*y ) ;
+double norm( double x, double y ) {
+    return sqrt( x*x + y*y );
 }
 
-RCPP_MODULE(mod_formals){
-        function( "norm", &norm,
-            List::create( _["x"] = 0.0, _["y"] = 0.0 ),
-            "Provides a simple vector norm"
-        ) ;
+RCPP_MODULE(mod_formals) {
+     function( "norm",
+              &norm,
+              List::create( _["x"] = 0.0, _["y"] = 0.0 ),
+              "Provides a simple vector norm");
 }
 @
 
@@ -446,17 +446,16 @@
 
 <<echo=FALSE,results=hide>>=
 fx_form <- cxxfunction( , '', includes = '
-using namespace Rcpp ;
+using namespace Rcpp;
 
-double norm( double x, double y ){
-        return sqrt( x*x + y*y ) ;
+double norm( double x, double y ) {
+    return sqrt( x*x + y*y );
 }
 
-RCPP_MODULE(mod_formals){
-        function( "norm", &norm,
-            List::create( _["x"] = 0.0, _["y"] = 0.0 ),
-            "Provides a simple vector norm"
-        ) ;
+RCPP_MODULE(mod_formals) {
+     function( "norm", &norm,
+              List::create( _["x"] = 0.0, _["y"] = 0.0 ),
+              "Provides a simple vector norm");
 }
 ', plugin = "Rcpp" )
 mod <- Module( "mod_formals", getDynLib( fx_form ), mustStart = TRUE )
@@ -472,17 +471,16 @@
 To set formal arguments without default values, simply omit the rhs.
 
 <<lang=cpp>>=
-using namespace Rcpp ;
+using namespace Rcpp;
 
-double norm( double x, double y ){
-	return sqrt( x*x + y*y ) ;
+double norm( double x, double y ) {
+    return sqrt( x*x + y*y );
 }
 
-RCPP_MODULE(mod_formals2){
-	function( "norm", &norm,
-	    List::create( _["x"], _["y"] = 0.0 ),
-	    "Provides a simple vector norm"
-	) ;
+RCPP_MODULE(mod_formals2) {
+    function( "norm", &norm,
+             List::create( _["x"], _["y"] = 0.0 ),
+             "Provides a simple vector norm");
 }
 @
 
@@ -490,17 +488,16 @@
 
 <<echo=FALSE,results=hide>>=
 fx_form2 <- cxxfunction( , '', includes = '
-using namespace Rcpp ;
+using namespace Rcpp;
 
-double norm( double x, double y ){
-	return sqrt( x*x + y*y ) ;
+double norm( double x, double y ) {
+    return sqrt( x*x + y*y );
 }
 
-RCPP_MODULE(mod_formals2){
-	function( "norm", &norm,
-	    List::create( _["x"], _["y"] = 0.0 ),
-	    "Provides a simple vector norm"
-	) ;
+RCPP_MODULE(mod_formals2) {
+        function( "norm", &norm,
+                 List::create( _["x"], _["y"] = 0.0 ),
+                 "Provides a simple vector norm");
 }
 ', plugin = "Rcpp" )
 mod <- Module( "mod_formals2", getDynLib( fx_form2 ), mustStart = TRUE )
@@ -514,32 +511,30 @@
 are optional; it does not take a default value.
 
 <<lang=cpp>>=
-using namespace Rcpp ;
+using namespace Rcpp;
 
-double norm( double x, double y ){
-	return sqrt( x*x + y*y ) ;
+double norm( double x, double y ) {
+    return sqrt( x*x + y*y );
 }
 
-RCPP_MODULE(mod_formals3){
-	function( "norm", &norm,
-	    List::create( _["x"], _["..."] ),
-	    "documentation for norm"
-	) ;
+RCPP_MODULE(mod_formals3) {
+    function( "norm", &norm,
+             List::create( _["x"], _["..."] ),
+             "documentation for norm");
 }
 @
 <<echo=FALSE,results=hide>>=
 fx_form3 <- cxxfunction( , '', includes = '
-using namespace Rcpp ;
+using namespace Rcpp;
 
-double norm( double x, double y ){
-	return sqrt( x*x + y*y ) ;
+double norm( double x, double y ) {
+    return sqrt( x*x + y*y );
 }
 
-RCPP_MODULE(mod_formals3){
-	function( "norm", &norm,
-	    List::create( _["x"] , _["..."]  ),
-	    "documentation for norm"
-	) ;
+RCPP_MODULE(mod_formals3) {
+    function( "norm", &norm,
+             List::create( _["x"] , _["..."]  ),
+             "documentation for norm");
 }
 ', plugin = "Rcpp" )
 mod <- Module( "mod_formals3", getDynLib( fx_form3 ), mustStart = TRUE )
@@ -561,70 +556,70 @@
 class may be exposed to \proglang{R} as follows:
 
 <<lang=cpp>>=
-using namespace Rcpp ;
+using namespace Rcpp;
 class Uniform {
 public:
-    Uniform(double min_, double max_) : min(min_), max(max_){}
+    Uniform(double min_, double max_) : min(min_), max(max_) {}
 
     NumericVector draw(int n) const {
-        RNGScope scope ;
-        return runif( n, min, max ) ;
+        RNGScope scope;
+        return runif( n, min, max );
     }
 
-    double min, max ;
+    double min, max;
 };
 
-double range( Uniform* w){
-	return w->max - w->min ;
+double range( Uniform* w) {
+    return w->max - w->min;
 }
 
-RCPP_MODULE(unif_module){
+RCPP_MODULE(unif_module) {
 
-	class_<Uniform>( "Uniform" )
+    class_<Uniform>( "Uniform" )
 
-        .constructor<double,double>()
+    .constructor<double,double>()
 
-        .field( "min", &Uniform::min )
-        .field( "max", &Uniform::max )
+    .field( "min", &Uniform::min )
+    .field( "max", &Uniform::max )
 
-        .method( "draw", &World::draw )
-        .method( "range", &range )
-	;
+    .method( "draw", &World::draw )
+    .method( "range", &range )
+    ;
 
 }
 @
 
 <<results=hide,echo=FALSE>>=
 fx_unif <- cxxfunction( , "", includes = '
-using namespace Rcpp ;
+using namespace Rcpp;
 class Uniform {
 public:
-    Uniform(double min_, double max_) : min(min_), max(max_){}
+    Uniform(double min_, double max_) : min(min_), max(max_) {}
 
     NumericVector draw(int n) const {
-        RNGScope scope ;
-        return runif( n, min, max ) ;
+        RNGScope scope;
+        return runif( n, min, max );
     }
 
-    double min, max ;
+    double min, max;
 };
 
-double range( Uniform* w){
-	return w->max - w->min ;
+double range( Uniform* w) {
+    return w->max - w->min;
 }
 
-RCPP_MODULE(unif_module){
+RCPP_MODULE(unif_module) {
 
-	class_<Uniform>( "Uniform" )
+    class_<Uniform>( "Uniform" )
 
-	    .constructor<double,double>()
+    .constructor<double,double>()
 
-	    .field( "min", &Uniform::min )
-	    .field( "max", &Uniform::max )
+    .field( "min", &Uniform::min )
+    .field( "max", &Uniform::max )
 
-		.method( "draw", &Uniform::draw )
-		.method( "range", &range )
-	;
+    .method( "draw", &Uniform::draw )
+    .method( "range", &range )
+    ;
 
 }
 ', plugin = "Rcpp" )
@@ -664,7 +659,7 @@
 matching the following type :
 
 <<lang=cpp>>=
-typedef bool (*ValidConstructor)(SEXP*,int) ;
+typedef bool (*ValidConstructor)(SEXP*,int);
 @
 
 The validator can be used to implement dispatch to the appropriate constructor,
@@ -682,31 +677,31 @@
 illustrated in the example below :
 
 <<lang=cpp>>=
-using namespace Rcpp ;
+using namespace Rcpp;
 class Foo {
     public:
         Foo( double x_, double y_, double z_ ):
-            x(x_), y(y_), z(z_){}
+            x(x_), y(y_), z(z_) {}
 
-        double x ;
-        double y ;
+        double x;
+        double y;
 
-        double get_z(){ return z ; }
-        void set_z( double z_ ){ z = z_ ; }
+        double get_z() { return z; }
+        void set_z( double z_ ) { z = z_; }
 
     private:
-        double z ;
-} ;
+        double z;
+};
 
-RCPP_MODULE(mod_foo){
+RCPP_MODULE(mod_foo) {
     class_<Foo>( "Foo" )
 
-        .constructor<double,double,double>()
+    .constructor<double,double,double>()
 
-        .field( "x", &Foo::x )
-        .field_readonly( "y", &Foo::y )
+    .field( "x", &Foo::x )
+    .field_readonly( "y", &Foo::y )
 
-        .property( "z", &Foo::get_z, &Foo::set_z )
+    .property( "z", &Foo::get_z, &Foo::set_z )
     ;
 }
 @
@@ -748,7 +743,7 @@
 class and returning a \textbf{T}, for example:
 
 <<lang=cpp>>=
-double z_get( Foo* foo ){ return foo->get_z() ; }
+double z_get( Foo* foo ) { return foo->get_z(); }
 @
 
 Setters can be either a member function taking a \texttt{T} and returning void, such
@@ -756,7 +751,7 @@
 class and a \textbf{T} :
 
 <<lang=cpp>>=
-void z_set( Foo* foo, double z ){ foo->set_z(z) ; }
+void z_set( Foo* foo, double z ) { foo->set_z(z); }
 @
 
 Using properties gives more flexibility in case field access has to be tracked
@@ -767,36 +762,36 @@
 class Bar {
     public:
 
-        Bar(double x_) : x(x_), nread(0), nwrite(0){}
+        Bar(double x_) : x(x_), nread(0), nwrite(0) {}
 
-        double get_x( ){
-            nread++ ;
-            return x ;
+        double get_x( ) {
+            nread++;
+            return x;
         }
 
-        void set_x( double x_){
-            nwrite++ ;
-            x = x_ ;
+        void set_x( double x_) {
+            nwrite++;
+            x = x_;
         }
 
         IntegerVector stats() const {
             return IntegerVector::create(
                 _["read"] = nread,
                 _["write"] = nwrite
-            ) ;
+            );
         }
 
     private:
         double x;
-        int nread, nwrite ;
+        int nread, nwrite;
 }
-RCPP_MODULE(mod_bar){
+RCPP_MODULE(mod_bar) {
     class_<Bar>( "Bar" )
 
-        .constructor<double>()
+    .constructor<double>()
 
-        .property( "x", &Bar::get_x, &Bar::set_x )
-        .method( "stats", &Bar::stats )
+    .property( "x", &Bar::get_x, &Bar::set_x )
+    .method( "stats", &Bar::stats )
     ;
 }
 @
@@ -808,31 +803,31 @@
 class Bar {
     public:
 
-        Bar(double x_) : x(x_), nread(0), nwrite(0){}
+        Bar(double x_) : x(x_), nread(0), nwrite(0) {}
 
-        double get_x( ){
-            nread++ ;
-            return x ;
+        double get_x( ) {
+            nread++;
+            return x;
         }
 
-        void set_x( double x_){
-            nwrite++ ;
-            x = x_ ;
+        void set_x( double x_) {
+            nwrite++;
+            x = x_;
         }
 
         IntegerVector stats() const {
             return IntegerVector::create(
                 _["read"] = nread,
                 _["write"] = nwrite
-            ) ;
+            );
         }
 
     private:
         double x;
-        int nread, nwrite ;
-} ;
+        int nread, nwrite;
+};
 
-RCPP_MODULE(mod_bar){
+RCPP_MODULE(mod_bar) {
     class_<Bar>( "Bar" )
 
         .constructor<double>()
@@ -928,9 +923,9 @@
 method for \proglang{C++} \texttt{World} objects:
 
 <<eval=FALSE>>=
-setMethod( "show", yada$World , function(object){
-	msg <- paste( "World object with message : ", object$greet() )
-	writeLines( msg )
+setMethod( "show", yada$World , function(object) {
+    msg <- paste( "World object with message : ", object$greet() )
+    writeLines( msg )
 } )
 @
 
@@ -945,28 +940,28 @@
 
 <<lang=cpp>>=
 // convenience typedef
-typedef std::vector<double> vec ;
+typedef std::vector<double> vec;
 
 // helpers
-void vec_assign( vec* obj, Rcpp::NumericVector data ){
-	obj->assign( data.begin(), data.end() ) ;
+void vec_assign( vec* obj, Rcpp::NumericVector data ) {
+    obj->assign( data.begin(), data.end() );
 }
 
-void vec_insert( vec* obj, int position, Rcpp::NumericVector data){
-	vec::iterator it = obj->begin() + position ;
-	obj->insert( it, data.begin(), data.end() ) ;
+void vec_insert( vec* obj, int position, Rcpp::NumericVector data) {
+    vec::iterator it = obj->begin() + position;
+    obj->insert( it, data.begin(), data.end() );
 }
 
-Rcpp::NumericVector vec_asR( vec* obj ){
-	return Rcpp::wrap( *obj ) ;
+Rcpp::NumericVector vec_asR( vec* obj ) {
+    return Rcpp::wrap( *obj );
 }
 
-void vec_set( vec* obj, int i, double value ){
-	obj->at( i ) = value ;
+void vec_set( vec* obj, int i, double value ) {
+    obj->at( i ) = value;
 }
 
-RCPP_MODULE(mod_vec){
-    using namespace Rcpp ;
+RCPP_MODULE(mod_vec) {
+    using namespace Rcpp;
 
     // we expose the class std::vector<double> as "vec" on the R side
     class_<vec>( "vec")
@@ -1001,35 +996,35 @@
     .const_method( "[[", &vec::at )
     .method( "[[<-", &vec_set )
 
-	;
+    ;
 }
 @
 
 <<echo=FALSE,results=hide>>=
 fx_vec <- cxxfunction(, '', includes = '
 // convenience typedef
-typedef std::vector<double> vec ;
+typedef std::vector<double> vec;
 
 // helpers
-void vec_assign( vec* obj, Rcpp::NumericVector data ){
-	obj->assign( data.begin(), data.end() ) ;
+void vec_assign( vec* obj, Rcpp::NumericVector data ) {
+    obj->assign( data.begin(), data.end() );
 }
 
-void vec_insert( vec* obj, int position, Rcpp::NumericVector data){
-	vec::iterator it = obj->begin() + position ;
-	obj->insert( it, data.begin(), data.end() ) ;
+void vec_insert( vec* obj, int position, Rcpp::NumericVector data) {
+    vec::iterator it = obj->begin() + position;
+    obj->insert( it, data.begin(), data.end() );
 }
 
-Rcpp::NumericVector vec_asR( vec* obj ){
-	return Rcpp::wrap( *obj ) ;
+Rcpp::NumericVector vec_asR( vec* obj ) {
+    return Rcpp::wrap( *obj );
 }
 
-void vec_set( vec* obj, int i, double value ){
-	obj->at( i ) = value ;
+void vec_set( vec* obj, int i, double value ) {
+    obj->at( i ) = value;
 }
 
-RCPP_MODULE(mod_vec){
-    using namespace Rcpp ;
+RCPP_MODULE(mod_vec) {
+    using namespace Rcpp;
 
     // we expose the class std::vector<double> as "vec" on the R side
     class_<vec>( "vec")
@@ -1064,7 +1059,7 @@
     .const_method( "[[", &vec::at )
     .method( "[[<-", &vec_set )
 
-	;
+    ;
 }
 ', plugin = "Rcpp" )
 mod_vec <- Module( "mod_vec", getDynLib(fx_vec), mustStart = TRUE )
@@ -1108,10 +1103,10 @@
 # grab the namespace
 NAMESPACE <- environment()
 
-.onLoad <- function(libname, pkgname){
-	# load the module and store it in our namespace
-	yada <- Module( "yada" )
-	populate( yada, NAMESPACE  )
+.onLoad <- function(libname, pkgname) {
+    ## load the module and store it in our namespace
+    yada <- Module( "yada" )
+    populate( yada, NAMESPACE  )
 }
 @
 
@@ -1135,7 +1130,7 @@
 
 yada <- Module( "yada" )
 
-.onLoad <- function(libname, pkgname){
+.onLoad <- function(libname, pkgname) {
     # placeholder
 }
 @



More information about the Rcpp-commits mailing list