[Rinside-commits] r205 - in pkg: . inst/examples/standard

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Apr 16 17:27:32 CEST 2011


Author: edd
Date: 2011-04-16 17:27:32 +0200 (Sat, 16 Apr 2011)
New Revision: 205

Added:
   pkg/inst/examples/standard/rinside_sample12.cpp
Modified:
   pkg/ChangeLog
Log:
add another rcpp-devel based example


Modified: pkg/ChangeLog
===================================================================
--- pkg/ChangeLog	2011-04-16 15:13:02 UTC (rev 204)
+++ pkg/ChangeLog	2011-04-16 15:27:32 UTC (rev 205)
@@ -1,5 +1,8 @@
 2011-04-16  Dirk Eddelbuettel  <edd at debian.org>
 
+	* inst/examples/standard/rinside_sample12.cpp: Another rcpp-devel
+	post leading to another simple and self-contained example
+
 	* inst/NEWS: Added, at long last, with backfills based on the
 	ChangeLog and blog postings
 

Added: pkg/inst/examples/standard/rinside_sample12.cpp
===================================================================
--- pkg/inst/examples/standard/rinside_sample12.cpp	                        (rev 0)
+++ pkg/inst/examples/standard/rinside_sample12.cpp	2011-04-16 15:27:32 UTC (rev 205)
@@ -0,0 +1,29 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4;  tab-width: 8; -*-
+//
+// Simple example motivated by post(s) from Nandan Amar to to rcpp-devel
+//
+// Copyright (C) 2011  Dirk Eddelbuettel and Romain Francois
+
+#include <RInside.h>                    // for the embedded R via RInside
+
+int main(int argc, char *argv[]) {
+
+    RInside R(argc, argv);    		// create an embedded R instance
+
+    std::string cmd = 			// evaluate an R expression with curve()
+	"tmpf <- tempfile('curve'); "	// get a temp. file
+	"png(tmpf); "			// open a PNG device
+	"curve(x^2, -10, 10, 200); "	// plot
+	"dev.off();"			// properly close device
+	"tmpf";				// filename as last value in expression
+    std::string tfile = R.parseEval(cmd);// we get the last assignment, here the filename
+
+    std::cout << "Could now use plot in " << tfile << std::endl;
+    unlink(tfile.c_str()); 		// cleaning up
+    
+    // alternatively, by explicitly opening a display we can plot to screen
+    cmd = "x11(); curve(x^2, -10, 10, 200); Sys.sleep(30);";
+    R.parseEvalQ(cmd);			// parseEvalQ evluates without assignment
+    
+    exit(0);
+}



More information about the Rinside-commits mailing list