[Rinside-commits] r96 - pkg/inst/examples

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Feb 9 03:38:38 CET 2010


Author: edd
Date: 2010-02-09 03:38:34 +0100 (Tue, 09 Feb 2010)
New Revision: 96

Added:
   pkg/inst/examples/rinside_sample6.cpp
Log:
new example showing off some templated assign uses


Added: pkg/inst/examples/rinside_sample6.cpp
===================================================================
--- pkg/inst/examples/rinside_sample6.cpp	                        (rev 0)
+++ pkg/inst/examples/rinside_sample6.cpp	2010-02-09 02:38:34 UTC (rev 96)
@@ -0,0 +1,49 @@
+
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4;  tab-width: 8; -*-
+//
+// Showing off some of the templated conversion due to Rcpp
+//
+// Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois and GPL'ed 
+
+#include "RInside.h"                    // for the embedded R via RInside
+
+int main(int argc, char *argv[]) {
+
+    try {
+
+        RInside R(argc, argv);          // create an embedded R instance 
+
+	double d1 = 1.234;		// scalar double
+	R.assign(d1, "d1");
+
+	std::vector<double> d2;		// vector of doubles
+	d2.push_back(1.23);
+	d2.push_back(4.56);
+	R.assign(d2, "d2");
+
+	std::map< std::string, double > d3; // map of doubles
+	d3["a"] = 7.89;
+	d3["b"] = 7.07;
+	R.assign(d3, "d3");
+
+	std::list< double > d4; 	// list of doubles
+	d4.push_back(1.11);
+	d4.push_back(4.44);
+	R.assign(d4, "d4");
+
+	std::string txt = 		// now access in R
+	    "cat('\nd1=', d1, '\n'); print(class(d1));"
+	    "cat('\nd2=\n'); print(d2); print(class(d2));"
+	    "cat('\nd3=\n'); print(d3); print(class(d3));"
+	    "cat('\nd4=\n'); print(d4); print(class(d4));";
+        R.parseEvalQ(txt);
+        
+    } catch(std::exception& ex) {
+        std::cerr << "Exception caught: " << ex.what() << std::endl;
+    } catch(...) {
+        std::cerr << "Unknown exception caught" << std::endl;
+    }
+
+    exit(0);
+}
+



More information about the Rinside-commits mailing list