[Rinside-commits] r186 - in pkg: . inst/examples/standard
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Mar 6 15:56:53 CET 2011
Author: edd
Date: 2011-03-06 15:56:53 +0100 (Sun, 06 Mar 2011)
New Revision: 186
Added:
pkg/inst/examples/standard/rinside_sample11.cpp
Modified:
pkg/ChangeLog
Log:
new example
Modified: pkg/ChangeLog
===================================================================
--- pkg/ChangeLog 2011-02-17 23:07:29 UTC (rev 185)
+++ pkg/ChangeLog 2011-03-06 14:56:53 UTC (rev 186)
@@ -1,3 +1,8 @@
+2011-03-06 Dirk Eddelbuettel <edd at debian.org>
+
+ * inst/examples/standard/rinside_sample11.cpp: New example in
+ response to r-help question by Paul Smith
+
2011-02-17 Dirk Eddelbuettel <edd at debian.org>
* inst/examples/standard/rinside_sample6.cpp: Updated to
@@ -11,7 +16,7 @@
2011-01-20 Dirk Eddelbuettel <edd at debian.org>
* src/RInside.cpp (initialize): Assign results of Rf_install to avoid
- any risk of garbage collection -- with thaks to Doug and Luke
+ any risk of garbage collection -- with thanks to Doug and Luke
2010-12-26 Dirk Eddelbuettel <edd at debian.org>
Added: pkg/inst/examples/standard/rinside_sample11.cpp
===================================================================
--- pkg/inst/examples/standard/rinside_sample11.cpp (rev 0)
+++ pkg/inst/examples/standard/rinside_sample11.cpp 2011-03-06 14:56:53 UTC (rev 186)
@@ -0,0 +1,33 @@
+// Simple example motivated by post from Paul Smith <phhs80 at gmail.com>
+// to r-help on 06 Mar 2011
+//
+// Copyright (C) 2011 Dirk Eddelbuettel and Romain Francois
+
+#include <RInside.h> // for the embedded R via RInside
+
+int main(int argc, char *argv[]) {
+
+ // create an embedded R instance
+ RInside R(argc, argv);
+
+ // evaluate an R expression with curve()
+ // because RInside defaults to interactive=false we use a file
+ std::string cmd = "tmpf <- tempfile('curve'); "
+ "png(tmpf); "
+ "curve(x^2, -10, 10, 200); "
+ "dev.off();"
+ "tmpf";
+ // by running parseEval, we get the last assignment back, here the filename
+ std::string tmpfile = R.parseEval(cmd);
+
+ std::cout << "Could now use plot in " << tmpfile << std::endl;
+ unlink(tmpfile.c_str()); // cleaning up
+
+ // alternatively, by forcing a display we can plot to screen
+ cmd = "x11(); curve(x^2, -10, 10, 200); Sys.sleep(30);";
+ // parseEvalQ evluates without assignment
+ R.parseEvalQ(cmd);
+
+ exit(0);
+}
+
More information about the Rinside-commits
mailing list