[Rinside-commits] r168 - in pkg: inst inst/examples/standard src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jun 16 14:42:26 CEST 2010


Author: romain
Date: 2010-06-16 14:42:26 +0200 (Wed, 16 Jun 2010)
New Revision: 168

Added:
   pkg/inst/examples/standard/rinside_module_sample0.cpp
Modified:
   pkg/inst/ChangeLog
   pkg/src/RInside.cpp
Log:
loading Rcpp and added an example of using an Rcpp module

Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog	2010-06-16 09:13:44 UTC (rev 167)
+++ pkg/inst/ChangeLog	2010-06-16 12:42:26 UTC (rev 168)
@@ -3,10 +3,15 @@
 	* inst/examples/standard/rinside_sample9.cpp: new example illustrating 
 	how to expose a C++ function to the embedded R
 	
+	* inst/examples/standard/rinside_module_sample0.cpp: new example illustrating 
+	how to use an Rcpp module from RInside
+
 	* inst/include/*.h: moved the headers to include so that there is only one copy
 	
 	* inst/include/MemBuf.h: change from signature of add to use
 	const std::string& instead of const char* 
+	
+	* src/RInside.cpp: loading the Rcpp package
 
 2010-04-21  Dirk Eddelbuettel  <edd at debian.org>
 

Added: pkg/inst/examples/standard/rinside_module_sample0.cpp
===================================================================
--- pkg/inst/examples/standard/rinside_module_sample0.cpp	                        (rev 0)
+++ pkg/inst/examples/standard/rinside_module_sample0.cpp	2010-06-16 12:42:26 UTC (rev 168)
@@ -0,0 +1,34 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4;  tab-width: 8; -*-
+//
+// Simple example showing how expose a C++ function
+//
+// Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois
+
+#include <RInside.h>                    // for the embedded R via RInside
+
+// a c++ function we wish to expose to R
+const char* hello( std::string who ){
+        std::string result( "hello " ) ;
+        result += who ;
+        return result.c_str() ;
+} 
+
+RCPP_MODULE(bling){
+	using namespace Rcpp ;
+	function( "hello", &hello );
+}
+
+int main(int argc, char *argv[]) {
+
+	// create an embedded R instance
+    RInside R(argc, argv);               
+        
+    // load the bling module
+    R["bling"] = LOAD_RCPP_MODULE(bling) ;
+    
+    // call it and display the result
+    std::string result = R.parseEval("bling$hello('world')") ;
+    std::cout << "bling$hello( 'world') =  '" << result << "'" << std::endl ; 
+    exit(0);
+}
+

Modified: pkg/src/RInside.cpp
===================================================================
--- pkg/src/RInside.cpp	2010-06-16 09:13:44 UTC (rev 167)
+++ pkg/src/RInside.cpp	2010-06-16 12:42:26 UTC (rev 168)
@@ -120,6 +120,11 @@
     
     autoloads();    		// Force all default package to be dynamically required */
 
+    // load Rcpp
+    Rf_PrintValue( 
+    	Rf_eval( Rf_lang2( Rf_install( "require" ), Rf_mkString("Rcpp") ), R_GlobalEnv ) 
+    	) ;
+    
     if ((argc - optind) > 1){    	// for argv vector in Global Env */
 	Rcpp::CharacterVector s_argv( argv+(1+optind), argv+argc );
 	assign(s_argv, "argv");



More information about the Rinside-commits mailing list