[Rcpp-commits] r1332 - pkg/Rcpp/inst/doc/snippets

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu May 27 11:23:07 CEST 2010


Author: romain
Date: 2010-05-27 11:23:07 +0200 (Thu, 27 May 2010)
New Revision: 1332

Added:
   pkg/Rcpp/inst/doc/snippets/WorldModule.cpp
   pkg/Rcpp/inst/doc/snippets/WorldModuleR.R
   pkg/Rcpp/inst/doc/snippets/functions.cpp
   pkg/Rcpp/inst/doc/snippets/functionsModule.cpp
   pkg/Rcpp/inst/doc/snippets/functionsModuleR.R
   pkg/Rcpp/inst/doc/snippets/helloModule.cpp
   pkg/Rcpp/inst/doc/snippets/helloModuleR.cpp
Log:
more code snippets used by the Rcpp-modules vignette

Added: pkg/Rcpp/inst/doc/snippets/WorldModule.cpp
===================================================================
--- pkg/Rcpp/inst/doc/snippets/WorldModule.cpp	                        (rev 0)
+++ pkg/Rcpp/inst/doc/snippets/WorldModule.cpp	2010-05-27 09:23:07 UTC (rev 1332)
@@ -0,0 +1,20 @@
+class World {
+public:
+    World() : msg("hello"){}
+    void set(std::string msg) { this->msg = msg; }
+    std::string greet() { return msg; }
+
+private:
+    std::string msg;
+};
+
+RCPP_MODULE(yada){
+	using namespace Rcpp ;
+	
+	class_<World>( "World" )
+		.method( "greet", &World::greet )
+		.method( "set", &World::set )
+	;
+
+}                     
+

Added: pkg/Rcpp/inst/doc/snippets/WorldModuleR.R
===================================================================
--- pkg/Rcpp/inst/doc/snippets/WorldModuleR.R	                        (rev 0)
+++ pkg/Rcpp/inst/doc/snippets/WorldModuleR.R	2010-05-27 09:23:07 UTC (rev 1332)
@@ -0,0 +1,16 @@
+require( Rcpp )
+
+# load the module
+yada <- Module( "yada" )
+
+# grab the World class
+World <- yada$World
+
+# create a new World object
+w <- new( World )
+
+# use methods of the class
+w$greet()
+w$set( "hello world" ) 
+w$greet()
+

Added: pkg/Rcpp/inst/doc/snippets/functions.cpp
===================================================================
--- pkg/Rcpp/inst/doc/snippets/functions.cpp	                        (rev 0)
+++ pkg/Rcpp/inst/doc/snippets/functions.cpp	2010-05-27 09:23:07 UTC (rev 1332)
@@ -0,0 +1,24 @@
+std::string hello(){
+	return "hello" ;
+}
+
+int bar( int x){
+	return x*2 ;
+}
+        
+double foo( int x, double y){
+	return x * y ;
+}
+
+void bla( ){
+	Rprintf( "hello\\n" ) ;
+}
+
+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 ) ;
+}
+

Added: pkg/Rcpp/inst/doc/snippets/functionsModule.cpp
===================================================================
--- pkg/Rcpp/inst/doc/snippets/functionsModule.cpp	                        (rev 0)
+++ pkg/Rcpp/inst/doc/snippets/functionsModule.cpp	2010-05-27 09:23:07 UTC (rev 1332)
@@ -0,0 +1,11 @@
+RCPP_MODULE(yada){
+	using namespace Rcpp ;
+	
+	function( "hello" , &hello ) ;
+	function( "bar"   , &bar   ) ;
+	function( "foo"   , &foo   ) ;
+	function( "bla"   , &bla   ) ;
+	function( "bla1"  , &bla1   ) ;
+	function( "bla2"  , &bla2   ) ;
+}
+

Added: pkg/Rcpp/inst/doc/snippets/functionsModuleR.R
===================================================================
--- pkg/Rcpp/inst/doc/snippets/functionsModuleR.R	                        (rev 0)
+++ pkg/Rcpp/inst/doc/snippets/functionsModuleR.R	2010-05-27 09:23:07 UTC (rev 1332)
@@ -0,0 +1,10 @@
+require( Rcpp )
+
+yada <- Module( "yada" )
+yada$bar( 2L )
+yada$foo( 2L, 10.0 )
+yada$hello() 
+yada$bla() 
+yada$bla1( 2L) 
+yada$bla2( 2L, 5.0 )
+

Added: pkg/Rcpp/inst/doc/snippets/helloModule.cpp
===================================================================
--- pkg/Rcpp/inst/doc/snippets/helloModule.cpp	                        (rev 0)
+++ pkg/Rcpp/inst/doc/snippets/helloModule.cpp	2010-05-27 09:23:07 UTC (rev 1332)
@@ -0,0 +1,12 @@
+
+const char* hello( std::string who ){
+	std::string result( "hello " ) ;
+	result += who ; 
+	return result.c_str() ;
+}
+
+RCPP_MODULE(yada){
+	using namespace Rcpp ;
+	function( "hello", &hello ) ;
+}
+

Added: pkg/Rcpp/inst/doc/snippets/helloModuleR.cpp
===================================================================
--- pkg/Rcpp/inst/doc/snippets/helloModuleR.cpp	                        (rev 0)
+++ pkg/Rcpp/inst/doc/snippets/helloModuleR.cpp	2010-05-27 09:23:07 UTC (rev 1332)
@@ -0,0 +1,3 @@
+require( Rcpp )
+yada <- Module( "yada" )
+yada$hello( "world" )



More information about the Rcpp-commits mailing list