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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Apr 9 00:27:52 CEST 2012


Author: edd
Date: 2012-04-09 00:27:52 +0200 (Mon, 09 Apr 2012)
New Revision: 237

Added:
   pkg/inst/examples/standard/rinside_sample12.cpp
Modified:
   pkg/ChangeLog
Log:
new (simple) example


Modified: pkg/ChangeLog
===================================================================
--- pkg/ChangeLog	2012-03-30 14:32:10 UTC (rev 236)
+++ pkg/ChangeLog	2012-04-08 22:27:52 UTC (rev 237)
@@ -1,3 +1,7 @@
+2012-04-08  Dirk Eddelbuettel  <edd at debian.org>
+
+	* inst/examples/standard/rinside_sample12.cpp: New example
+
 2012-03-30  Dirk Eddelbuettel  <edd at debian.org>
 
 	* inst/examples/wt/wtdensity.cpp: Extended / prettyfied Wt example to

Added: pkg/inst/examples/standard/rinside_sample12.cpp
===================================================================
--- pkg/inst/examples/standard/rinside_sample12.cpp	                        (rev 0)
+++ pkg/inst/examples/standard/rinside_sample12.cpp	2012-04-08 22:27:52 UTC (rev 237)
@@ -0,0 +1,24 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4;  tab-width: 8; -*-
+//
+// Simple example motivated by StackOverflow question on using sample() from C
+//
+// Copyright (C) 2012  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 = "set.seed(123); sample(LETTERS[1:5], 10, replace=TRUE)";
+
+    Rcpp::CharacterVector res = R.parseEval(cmd); // parse, eval + return result
+
+    for (int i=0; i<res.size(); i++) {
+	std::cout << res[i] << " ";
+    }
+    std::cout << std::endl;
+    
+    exit(0);
+}
+



More information about the Rinside-commits mailing list