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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Mar 25 23:04:29 CET 2010


Author: edd
Date: 2010-03-25 23:04:29 +0100 (Thu, 25 Mar 2010)
New Revision: 141

Modified:
   pkg/inst/ChangeLog
   pkg/inst/examples/standard/rinside_sample8.cpp
   pkg/src/RInside.h
Log:
new Proxy() class to use Rcpp wrappers on left-hand side of assigment
sample use in rinside_sample8.cpp


Modified: pkg/inst/ChangeLog
===================================================================
--- pkg/inst/ChangeLog	2010-03-25 15:11:55 UTC (rev 140)
+++ pkg/inst/ChangeLog	2010-03-25 22:04:29 UTC (rev 141)
@@ -1,3 +1,9 @@
+2010-03-25  Dirk Eddelbuettel  <edd at debian.org>
+
+	* src/RInside.h: New Proxy class with operator T() to borrow
+	  Rcpp's automatic wrappers
+	* inst/examples/standard/rinside_sample8.cpp: Use Proxy()
+
 2010-03-22  Dirk Eddelbuettel  <edd at debian.org>
 
 	* DESCRIPTION: Increase Version: to 0.2.2

Modified: pkg/inst/examples/standard/rinside_sample8.cpp
===================================================================
--- pkg/inst/examples/standard/rinside_sample8.cpp	2010-03-25 15:11:55 UTC (rev 140)
+++ pkg/inst/examples/standard/rinside_sample8.cpp	2010-03-25 22:04:29 UTC (rev 141)
@@ -21,6 +21,10 @@
     sum = Rcpp::as<int>( R.parseEval("z <- x + y") ); 
     std::cout << "10 + 20 = " << sum << std::endl ; 
 
+    // Or we can use the Proxy() class
+    sum = Proxy( R.parseEval("z <- x + y") ); 
+    std::cout << "10 + 20 = " << sum << std::endl ; 
+
     exit(0);
 }
 

Modified: pkg/src/RInside.h
===================================================================
--- pkg/src/RInside.h	2010-03-25 15:11:55 UTC (rev 140)
+++ pkg/src/RInside.h	2010-03-25 22:04:29 UTC (rev 141)
@@ -66,6 +66,18 @@
     
 };
 
+class Proxy {
+public:
+    Proxy(SEXP xx): x(xx) { };
+
+    template <typename T>
+    operator T() {
+	return ::Rcpp::as<T>(x);
+    }
+private:
+    Rcpp::RObject x;
+};
+
 // simple logging help
 inline void logTxtFunction(const char* file, const int line, const char* expression, const bool verbose) {
     if (verbose) {



More information about the Rinside-commits mailing list