[Rinside-commits] r98 - in pkg: . inst inst/examples src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Feb 12 15:10:47 CET 2010


Author: romain
Date: 2010-02-12 15:10:46 +0100 (Fri, 12 Feb 2010)
New Revision: 98

Added:
   pkg/inst/examples/rinside_sample8.cpp
Modified:
   pkg/DESCRIPTION
   pkg/inst/ChangeLog
   pkg/src/RInside.cpp
   pkg/src/RInside.h
Log:
added RInside::operator[](string)

Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION	2010-02-09 03:49:19 UTC (rev 97)
+++ pkg/DESCRIPTION	2010-02-12 14:10:46 UTC (rev 98)
@@ -15,7 +15,7 @@
  Several examples are provided in the examples/ directory of
  the installed package, and Doxygen-generated documentation of
  the C++ classes is included as well.
-Depends: R (>= 2.10.0), Rcpp (>= 0.7.4.2)
+Depends: R (>= 2.10.0), Rcpp (>= 0.7.5.2)
 SystemRequirements: None
 URL: http://dirk.eddelbuettel.com/code/rinside.html
 License: GPL-2

Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog	2010-02-09 03:49:19 UTC (rev 97)
+++ pkg/inst/ChangeLog	2010-02-12 14:10:46 UTC (rev 98)
@@ -1,3 +1,10 @@
+2010-02-12  Romain Francois <romain at r-enthusiasts.com>
+
+	* src/RInside.h: RInside gains an operator[](string) to allow
+	treating the RInside instance as a proxy to the global environment
+	so that we can do: RInside R; R["x"] = 10 ; All the actual work
+	is done by the Rcpp::Environment class
+
 2010-02-04  Romain Francois <francoisromain at free.fr>
 
 	* RInside::autoloads revisited with the new Rcpp api

Added: pkg/inst/examples/rinside_sample8.cpp
===================================================================
--- pkg/inst/examples/rinside_sample8.cpp	                        (rev 0)
+++ pkg/inst/examples/rinside_sample8.cpp	2010-02-12 14:10:46 UTC (rev 98)
@@ -0,0 +1,22 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4;  tab-width: 8; -*-
+//
+// Simple example showing how to use R[] = ; 
+//
+// Copyright (C) 2009 Dirk Eddelbuettel and GPL'ed 
+
+#include "RInside.h"                    // for the embedded R via RInside
+
+int main(int argc, char *argv[]) {
+
+    RInside R;              // create an embedded R instance 
+    
+    R["x"] = 10 ;
+    R["y"] = 20 ;
+
+    R.parseEvalQ("z <- x + y") ;
+    int sum = Rcpp::as<int>( R["z"] ); 
+  
+    std::cout << "10 + 20 = " << sum << std::endl ; 
+    exit(0);
+}
+

Modified: pkg/src/RInside.cpp
===================================================================
--- pkg/src/RInside.cpp	2010-02-09 03:49:19 UTC (rev 97)
+++ pkg/src/RInside.cpp	2010-02-12 14:10:46 UTC (rev 98)
@@ -45,7 +45,7 @@
     logTxt("RInside::dtor END", verbose);
 }
 
-RInside::RInside(){
+RInside::RInside() {
 	initialize( 0, 0 );
 }
 
@@ -94,7 +94,8 @@
     R_SetParams(&Rst);
 
     //ptr_R_CleanUp = littler_CleanUp; --- we do that in the destructor
-
+    global_env = R_GlobalEnv ;
+    
     autoloads();    		// Force all default package to be dynamically required */
 
     if ((argc - optind) > 1){    	// for argv vector in Global Env */
@@ -106,6 +107,8 @@
   
     init_rand();    			// for tempfile() to work correctly */
     logTxt("RInside::ctor END", verbose);
+
+    
 }
 
 void RInside::init_tempdir(void) {
@@ -288,6 +291,10 @@
     return rc;
 }
 
+Rcpp::Environment::Binding RInside::operator[]( const std::string& name ){
+	return global_env[name]; 
+}
+
 // specializations of Rcpp wrap template
 // this overwrites the default behaviour in Rcpp that would 
 // wrap vector<vector<double>> as lists of numeric vectors

Modified: pkg/src/RInside.h
===================================================================
--- pkg/src/RInside.h	2010-02-09 03:49:19 UTC (rev 97)
+++ pkg/src/RInside.h	2010-02-12 14:10:46 UTC (rev 98)
@@ -44,7 +44,8 @@
 class RInside {
 private:
     MemBuf mb_m;
-
+    Rcpp::Environment global_env ;
+    
     bool verbose_m;				// private switch
 
     void init_tempdir(void);
@@ -59,12 +60,15 @@
 
     template <typename T>
     void assign(const T& object, const std::string& nam){
-	Rcpp::Environment::global_env().assign( nam, object ) ;
+	global_env.assign( nam, object ) ;
     }
     
     RInside() ;
     RInside(const int argc, const char* const argv[]);
     ~RInside();
+    
+    Rcpp::Environment::Binding operator[]( const std::string& name ) ;
+    
 };
 
 // simple logging help



More information about the Rinside-commits mailing list