[Rinside-commits] r109 - in pkg/inst/examples: . standard
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Feb 19 05:25:56 CET 2010
Author: edd
Date: 2010-02-19 05:25:56 +0100 (Fri, 19 Feb 2010)
New Revision: 109
Added:
pkg/inst/examples/standard/
pkg/inst/examples/standard/Makefile
pkg/inst/examples/standard/Makefile.win
pkg/inst/examples/standard/rinside_sample0.cpp
pkg/inst/examples/standard/rinside_sample1.cpp
pkg/inst/examples/standard/rinside_sample2.cpp
pkg/inst/examples/standard/rinside_sample3.cpp
pkg/inst/examples/standard/rinside_sample4.cpp
pkg/inst/examples/standard/rinside_sample5.cpp
pkg/inst/examples/standard/rinside_sample6.cpp
pkg/inst/examples/standard/rinside_sample7.cpp
pkg/inst/examples/standard/rinside_sample8.cpp
pkg/inst/examples/standard/rinside_test0.cpp
pkg/inst/examples/standard/rinside_test1.cpp
Removed:
pkg/inst/examples/Makefile
pkg/inst/examples/Makefile.win
pkg/inst/examples/rinside_sample0.cpp
pkg/inst/examples/rinside_sample1.cpp
pkg/inst/examples/rinside_sample2.cpp
pkg/inst/examples/rinside_sample3.cpp
pkg/inst/examples/rinside_sample4.cpp
pkg/inst/examples/rinside_sample5.cpp
pkg/inst/examples/rinside_sample6.cpp
pkg/inst/examples/rinside_sample7.cpp
pkg/inst/examples/rinside_sample8.cpp
pkg/inst/examples/rinside_test0.cpp
pkg/inst/examples/rinside_test1.cpp
Log:
non-mpi examples now in directory standard/
Deleted: pkg/inst/examples/Makefile
===================================================================
--- pkg/inst/examples/Makefile 2010-02-18 02:12:13 UTC (rev 108)
+++ pkg/inst/examples/Makefile 2010-02-19 04:25:56 UTC (rev 109)
@@ -1,45 +0,0 @@
-## -*- mode: make; tab-width: 8; -*-
-##
-## Simple Makefile
-##
-## TODO:
-## proper configure for non-Debian file locations, [ Done ]
-## allow RHOME to be set for non-default R etc
-
-## comment this out if you need a different version of R,
-## and set set R_HOME accordingly as an environment variable
-R_HOME := $(shell R RHOME)
-
-sources := $(wildcard *.cpp)
-programs := $(sources:.cpp=)
-
-
-## include headers and libraries for R
-RCPPFLAGS := $(shell $(R_HOME)/bin/R CMD config --cppflags)
-RLDFLAGS := $(shell $(R_HOME)/bin/R CMD config --ldflags)
-RBLAS := $(shell $(R_HOME)/bin/R CMD config BLAS_LIBS)
-RLAPACK := $(shell $(R_HOME)/bin/R CMD config LAPACK_LIBS)
-
-
-## include headers and libraries for Rcpp interface classes
-RCPPINCL := $(shell echo 'Rcpp:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)
-RCPPLIBS := $(shell echo 'Rcpp:::LdFlags()' | $(R_HOME)/bin/R --vanilla --slave)
-
-
-## include headers and libraries for RInside embedding classes
-RINSIDEINCL := $(shell echo 'RInside:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)
-RINSIDELIBS := $(shell echo 'RInside:::LdFlags()' | $(R_HOME)/bin/R --vanilla --slave)
-
-
-## compiler etc settings used in default make rules
-CXX := $(shell $(R_HOME)/bin/R CMD config CXX)
-CPPFLAGS := -Wall $(shell $(R_HOME)/bin/R CMD config CPPFLAGS)
-CXXFLAGS := $(RCPPFLAGS) $(RCPPINCL) $(RINSIDEINCL) $(shell $(R_HOME)/bin/R CMD config CXXFLAGS)
-LDFLAGS = -s
-LDLIBS := $(RLDFLAGS) $(RBLAS) $(RLAPACK) $(RCPPLIBS) $(RINSIDELIBS)
-
-all : $(programs)
-
-clean:
- rm -vf $(programs)
-
Deleted: pkg/inst/examples/Makefile.win
===================================================================
--- pkg/inst/examples/Makefile.win 2010-02-18 02:12:13 UTC (rev 108)
+++ pkg/inst/examples/Makefile.win 2010-02-19 04:25:56 UTC (rev 109)
@@ -1,46 +0,0 @@
-## -*- mode: makefile; tab-width: 8; -*-
-##
-## Simple Makefile
-##
-## TODO:
-## proper configure for non-Debian file locations, [ Done ]
-## allow RHOME to be set for non-default R etc
-
-## comment this out if you need a different version of R,
-## and set set R_HOME accordingly as an environment variable
-#R_HOME := $(shell R RHOME)
-
-sources := $(wildcard *.cpp)
-programs := $(sources:.cpp=)
-
-
-## include headers and libraries for R
-RCPPFLAGS := $(shell $(R_HOME)/bin/R CMD config --cppflags)
-RLDFLAGS := $(shell $(R_HOME)/bin/R CMD config --ldflags)
-RBLAS := $(shell $(R_HOME)/bin/R CMD config BLAS_LIBS)
-RLAPACK := $(shell $(R_HOME)/bin/R CMD config LAPACK_LIBS)
-
-
-## include headers and libraries for Rcpp interface classes
-RCPPINCL := $(shell echo 'Rcpp:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)
-RCPPLIBS := $(shell echo 'Rcpp:::LdFlags()' | $(R_HOME)/bin/R --vanilla --slave)
-
-
-## include headers and libraries for RInside embedding classes
-RINSIDEINCL := $(shell echo 'RInside:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)
-RINSIDELIBS := $(shell echo 'RInside:::LdFlags()' | $(R_HOME)/bin/R --vanilla --slave)
-
-## compiler etc settings used in default make rules
-CXX := $(shell $(R_HOME)/bin/R CMD config CXX)
-CPPFLAGS := -Wall $(shell $(R_HOME)/bin/R CMD config CPPFLAGS)
-CXXFLAGS := $(RCPPFLAGS) $(RCPPINCL) $(RINSIDEINCL) $(shell $(R_HOME)/bin/R CMD config CXXFLAGS)
-LDFLAGS = -s
-LDLIBS := $(RLDFLAGS) $(RBLAS) $(RLAPACK) $(RCPPLIBS) $(RINSIDELIBS)
-CC := $(shell $(R_HOME)/bin/R CMD config CXX)
-
-
-all : $(programs)
-
-clean:
- rm -vf $(programs)
-
Deleted: pkg/inst/examples/rinside_sample0.cpp
===================================================================
--- pkg/inst/examples/rinside_sample0.cpp 2010-02-18 02:12:13 UTC (rev 108)
+++ pkg/inst/examples/rinside_sample0.cpp 2010-02-19 04:25:56 UTC (rev 109)
@@ -1,24 +0,0 @@
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8; -*-
-//
-// Simple example showing an overly complicated way to do the standard 'hello, world' example
-//
-// Copyright (C) 2009 Dirk Eddelbuettel
-// Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois
-//
-// GPL'ed
-
-#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 txt = "Hello, world!\n";// assign a standard C++ string to 'txt'
- R["txt"] = txt; // assign C++ string var to R variable 'txt'
-
- std::string evalstr = "cat(txt)";
- R.parseEvalQ(evalstr); // eval the init string, ignoring any returns
-
- exit(0);
-}
-
Deleted: pkg/inst/examples/rinside_sample1.cpp
===================================================================
--- pkg/inst/examples/rinside_sample1.cpp 2010-02-18 02:12:13 UTC (rev 108)
+++ pkg/inst/examples/rinside_sample1.cpp 2010-02-19 04:25:56 UTC (rev 109)
@@ -1,53 +0,0 @@
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8; -*-
-//
-// Simple example with data in C++ that is passed to R, processed and a result is extracted
-//
-// Copyright (C) 2009 Dirk Eddelbuettel
-// Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois
-//
-// GPL'ed
-
-#include "RInside.h" // for the embedded R via RInside
-
-std::vector< std::vector< double > >
-createMatrix(const int n) { // simple STL matrix content generator
- std::vector< std::vector< double > > mat;
- for (int i=0; i<n; i++) {
- std::vector<double> row;
- for (int j=0; j<n; j++) {
- row.push_back((i*10+j));
- }
- mat.push_back(row);
- }
- return(mat);
-}
-
-int main(int argc, char *argv[]) {
- const int mdim = 4;
- SEXP ans;
-
- RInside R(argc, argv); // create an embedded R instance
-
- // create and fill a sample data Matrix
- std::vector< std::vector< double > > myMatrix = createMatrix(mdim);
-
- R["M"] = myMatrix; // assign STL matrix to R's 'M' var
-
- std::string evalstr = "\
- cat('Running ls()\n'); print(ls()); \
- cat('Showing M\n'); print(M); \
- cat('Showing colSums()\n'); Z <- colSums(M); print(Z); \
- Z"; // returns Z
-
- R.parseEval(evalstr, ans); // eval the init string -- Z is now in ans
-
- // convert SEXP ans to a vector of doubles
- std::vector<double> v = Rcpp::as <std::vector<double> >(ans);
-
- for (unsigned int i=0; i< v.size(); i++) { // show the result
- std::cout << "In C++ element " << i << " is " << v[i] << std::endl;
- }
- exit(0);
-}
-
-
Deleted: pkg/inst/examples/rinside_sample2.cpp
===================================================================
--- pkg/inst/examples/rinside_sample2.cpp 2010-02-18 02:12:13 UTC (rev 108)
+++ pkg/inst/examples/rinside_sample2.cpp 2010-02-19 04:25:56 UTC (rev 109)
@@ -1,46 +0,0 @@
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8; -*-
-//
-// Simple example for the repeated r-devel mails by Abhijit Bera
-//
-// Copyright (C) 2009 Dirk Eddelbuettel 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
- SEXP ans;
-
- std::string txt = "suppressMessages(library(fPortfolio))";
- if (R.parseEvalQ(txt)) // load library, no return value
- throw std::runtime_error("R cannot evaluate '" + txt + "'");
-
- txt = "M <- as.matrix(SWX.RET); print(head(M)); M";
- if (R.parseEval(txt, ans)) // assign matrix M to SEXP variable ans
- throw std::runtime_error("R cannot evaluate '" + txt + "'");
- RcppMatrix<double> M(ans); // convert SEXP variable to an RcppMatrix
-
- std::cout << "M has "
- << M.getDim1() << " rows and "
- << M.getDim2() << " cols" << std::endl;
-
- txt = "colnames(M)";
- if (R.parseEval(txt, ans)) // assign columns names of M to ans
- throw std::runtime_error("R cannot evaluate '" + txt + "'");
- RcppStringVector cnames(ans); // and into string vector cnames
-
-
- for (int i=0; i<M.getDim2(); i++) {
- std::cout << "Column " << cnames(i) << " in row 42 has " << M(42,i) << std::endl;
- }
-
- } catch(std::exception& ex) {
- std::cerr << "Exception caught: " << ex.what() << std::endl;
- } catch(...) {
- std::cerr << "Unknown exception caught" << std::endl;
- }
-
- exit(0);
-}
-
Deleted: pkg/inst/examples/rinside_sample3.cpp
===================================================================
--- pkg/inst/examples/rinside_sample3.cpp 2010-02-18 02:12:13 UTC (rev 108)
+++ pkg/inst/examples/rinside_sample3.cpp 2010-02-19 04:25:56 UTC (rev 109)
@@ -1,47 +0,0 @@
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8; -*-
-//
-// Simple example for using lm() using the example from help(swiss)
-//
-// Copyright (C) 2009 Dirk Eddelbuettel and GPL'ed
-
-#include "RInside.h" // for the embedded R via RInside
-#include <iomanip>
-
-int main(int argc, char *argv[]) {
-
- RInside R(argc, argv); // create an embedded R instance
- SEXP ans;
-
- std::string txt = // load library, run regression, create summary
- "suppressMessages(require(stats));"
- "swisssum <- summary(lm(Fertility ~ . , data = swiss));"
- "print(swisssum)";
- R.parseEvalQ(txt); // eval command, no return
-
- txt = "swcoef <- coef(swisssum)";
- R.parseEval(txt, ans); // matrix swisscoef now in SEXP ans
- RcppMatrix<double> M(ans); // convert SEXP variable to an RcppMatrix
-
- R.parseEval("colnames(swcoef)",ans);// assign columns names to ans
- RcppStringVector cnames(ans); // and into string vector cnames
- R.parseEval("rownames(swcoef)",ans);// assign columns names to ans
- RcppStringVector rnames(ans); // and into string vector cnames
-
- std::cout << "\t\t\t";
- for (int i=0; i<cnames.size(); i++) {
- std::cout << std::setw(11) << cnames(i) << "\t";
- }
- std::cout << std::endl;
-
- for (int i=0; i<rnames.size(); i++) {
- std::cout << std::setw(16) << rnames(i) << "\t";
- for (int j=0; j<cnames.size(); j++) {
- std::cout << std::setw(11) << M(i,j) << "\t";
- }
- std::cout << std::endl;
- }
- std::cout << std::endl;
-
- exit(0);
-}
-
Deleted: pkg/inst/examples/rinside_sample4.cpp
===================================================================
--- pkg/inst/examples/rinside_sample4.cpp 2010-02-18 02:12:13 UTC (rev 108)
+++ pkg/inst/examples/rinside_sample4.cpp 2010-02-19 04:25:56 UTC (rev 109)
@@ -1,58 +0,0 @@
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8; -*-
-//
-// Another simple example inspired by an r-devel mail by Abhijit Bera
-//
-// Copyright (C) 2009 Dirk Eddelbuettel and GPL'ed
-
-#include "RInside.h" // for the embedded R via RInside
-#include <iomanip>
-
-int main(int argc, char *argv[]) {
-
- try {
- RInside R(argc, argv); // create an embedded R instance
- SEXP ans;
-
- std::string txt = "suppressMessages(library(fPortfolio))";
- if (R.parseEvalQ(txt)) // load library, no return value
- throw std::runtime_error("R cannot evaluate '" + txt + "'");
-
- txt = "lppData <- 100 * LPP2005.RET[, 1:6]; "
- "ewSpec <- portfolioSpec(); "
- "nAssets <- ncol(lppData); ";
- if (R.parseEval(txt, ans)) // prepare problem
- throw std::runtime_error("R cannot evaluate '" + txt + "'");
-
- const double dvec[6] = { 0.1, 0.1, 0.1, 0.1, 0.3, 0.3 }; // choose any weights you want
- const std::vector<double> w(dvec, &dvec[6]);
-
- R.assign( w, "weightsvec"); // assign STL vector to R's 'weightsvec' variable
-
- txt = "setWeights(ewSpec) <- weightsvec";
- if (R.parseEvalQ(txt)) // evaluate assignment
- throw std::runtime_error("R cannot evaluate '" + txt + "'");
-
- txt = "ewPortfolio <- feasiblePortfolio(data = lppData, spec = ewSpec, constraints = \"LongOnly\"); "
- "print(ewPortfolio); "
- "vec <- getCovRiskBudgets(ewPortfolio at portfolio)";
- if (R.parseEval(txt, ans)) // assign covRiskBudget weights to ans
- throw std::runtime_error("R cannot evaluate '" + txt + "'");
- RcppVector<double> V(ans); // convert SEXP variable to an RcppVector
-
- R.parseEval("names(vec)", ans); // assign columns names to ans
- RcppStringVector names(ans);
-
- for (int i=0; i<names.size(); i++) {
- std::cout << std::setw(16) << names(i) << "\t"
- << std::setw(11) << V(i) << "\n";
- }
-
- } catch(std::exception& ex) {
- std::cerr << "Exception caught: " << ex.what() << std::endl;
- } catch(...) {
- std::cerr << "Unknown exception caught" << std::endl;
- }
-
- exit(0);
-}
-
Deleted: pkg/inst/examples/rinside_sample5.cpp
===================================================================
--- pkg/inst/examples/rinside_sample5.cpp 2010-02-18 02:12:13 UTC (rev 108)
+++ pkg/inst/examples/rinside_sample5.cpp 2010-02-19 04:25:56 UTC (rev 109)
@@ -1,37 +0,0 @@
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8; -*-
-//
-// Another simple example inspired by an r-devel mail by Martin Becker
-//
-// Copyright (C) 2009 Dirk Eddelbuettel 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
- SEXP ans;
-
- std::string txt = "myenv <- new.env(hash=TRUE, size=NA)";
- if (R.parseEvalQ(txt)) // eval string quietly, no result
- throw std::runtime_error("R cannot evaluate '" + txt + "'");
-
- txt = "as.integer(is.environment(myenv))";
- if (R.parseEval(txt, ans)) // eval string, result in ans
- throw std::runtime_error("R cannot evaluate '" + txt + "'");
-
- RcppVector<int> V(ans); // convert SEXP variable to an RcppVector
-
- std::cout << "We "
- << (V(0) ? "do" : "do not")
- << " have an environment." << std::endl;
-
- } catch(std::exception& ex) {
- std::cerr << "Exception caught: " << ex.what() << std::endl;
- } catch(...) {
- std::cerr << "Unknown exception caught" << std::endl;
- }
-
- exit(0);
-}
-
Deleted: pkg/inst/examples/rinside_sample6.cpp
===================================================================
--- pkg/inst/examples/rinside_sample6.cpp 2010-02-18 02:12:13 UTC (rev 108)
+++ pkg/inst/examples/rinside_sample6.cpp 2010-02-19 04:25:56 UTC (rev 109)
@@ -1,49 +0,0 @@
-
-// -*- 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);
-}
-
Deleted: pkg/inst/examples/rinside_sample7.cpp
===================================================================
--- pkg/inst/examples/rinside_sample7.cpp 2010-02-18 02:12:13 UTC (rev 108)
+++ pkg/inst/examples/rinside_sample7.cpp 2010-02-19 04:25:56 UTC (rev 109)
@@ -1,36 +0,0 @@
-
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8; -*-
-//
-// Showing off some of the templated as<>() conversion from 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
- SEXP ans;
- std::string txt;
-
- txt = "m <- 1.23";
- R.parseEval(txt, ans);
- double d1 = Rcpp::as< double >(ans);
- std::cout << "d1 " << d1 << std::endl;
-
- txt = "M <- 1.0 * 1:6";
- R.parseEval(txt, ans);
- std::vector<double> d2 = Rcpp::as< std::vector< double > >(ans);
- std::cout << "d2[0] " << d2[0] << " d2[1] " << d2[1] << std::endl;
-
- } catch(std::exception& ex) {
- std::cerr << "Exception caught: " << ex.what() << std::endl;
- } catch(...) {
- std::cerr << "Unknown exception caught" << std::endl;
- }
-
- exit(0);
-}
-
Deleted: pkg/inst/examples/rinside_sample8.cpp
===================================================================
--- pkg/inst/examples/rinside_sample8.cpp 2010-02-18 02:12:13 UTC (rev 108)
+++ pkg/inst/examples/rinside_sample8.cpp 2010-02-19 04:25:56 UTC (rev 109)
@@ -1,22 +0,0 @@
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8; -*-
-//
-// Simple example showing how to use R[] = ;
-//
-// 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[]) {
-
- RInside R(argc, argv); // create an embedded R instance
-
- R["x"] = 10 ;
- R["y"] = 20 ;
-
- R.parseEvalQ("z <- x + y") ;
- int sum = Rcpp::as<int>( R["z"] );
-
- std::cout << "10 + 20 = " << sum << std::endl ;
- exit(0);
-}
-
Deleted: pkg/inst/examples/rinside_test0.cpp
===================================================================
--- pkg/inst/examples/rinside_test0.cpp 2010-02-18 02:12:13 UTC (rev 108)
+++ pkg/inst/examples/rinside_test0.cpp 2010-02-19 04:25:56 UTC (rev 109)
@@ -1,30 +0,0 @@
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8; -*-
-//
-// Simple test that did not trigger the bug reported by Miguel Lechón
-//
-// Copyright (C) 2009 Dirk Eddelbuettel and GPL'ed
-
-#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 txt = "Hello, world!\n";// assign a standard C++ string to 'txt'
- R.assign( txt, "txt"); // assign string var to R variable 'txt'
-
- std::string evalstr = "cat(txt)";
- for (int i=0; i<1e1; i++) {
- R.parseEvalQ(evalstr); // eval the init string, ignoring any returns
- }
- evalstr = "txt <- \"foo\\n\"";
- for (int i=0; i<1e6; i++) {
- R.parseEvalQ(evalstr); // eval the init string, ignoring any returns
- }
- evalstr = "cat(txt)";
- for (int i=0; i<1e1; i++) {
- R.parseEvalQ(evalstr); // eval the init string, ignoring any returns
- }
- exit(0);
-}
-
Deleted: pkg/inst/examples/rinside_test1.cpp
===================================================================
--- pkg/inst/examples/rinside_test1.cpp 2010-02-18 02:12:13 UTC (rev 108)
+++ pkg/inst/examples/rinside_test1.cpp 2010-02-19 04:25:56 UTC (rev 109)
@@ -1,22 +0,0 @@
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8; -*-
-//
-// Simple test that did trigger the bug reported by Miguel Lechón
-//
-// Copyright (C) 2009 Dirk Eddelbuettel and GPL'ed
-
-#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 txt = "Hello, world!\n";// assign a standard C++ string to 'txt'
- R.assign( txt, "txt"); // assign string var to R variable 'txt'
-
- std::string evalstr = "txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; txt <- \"foo\\n\"; cat(txt)";
- for (int i=0; i<1e1; i++) {
- R.parseEvalQ(evalstr); // eval the init string, ignoring any returns
- }
- exit(0);
-}
-
Copied: pkg/inst/examples/standard/Makefile (from rev 108, pkg/inst/examples/Makefile)
===================================================================
--- pkg/inst/examples/standard/Makefile (rev 0)
+++ pkg/inst/examples/standard/Makefile 2010-02-19 04:25:56 UTC (rev 109)
@@ -0,0 +1,45 @@
+## -*- mode: make; tab-width: 8; -*-
+##
+## Simple Makefile
+##
+## TODO:
+## proper configure for non-Debian file locations, [ Done ]
+## allow RHOME to be set for non-default R etc
+
+## comment this out if you need a different version of R,
+## and set set R_HOME accordingly as an environment variable
+R_HOME := $(shell R RHOME)
+
+sources := $(wildcard *.cpp)
+programs := $(sources:.cpp=)
+
+
+## include headers and libraries for R
+RCPPFLAGS := $(shell $(R_HOME)/bin/R CMD config --cppflags)
+RLDFLAGS := $(shell $(R_HOME)/bin/R CMD config --ldflags)
+RBLAS := $(shell $(R_HOME)/bin/R CMD config BLAS_LIBS)
+RLAPACK := $(shell $(R_HOME)/bin/R CMD config LAPACK_LIBS)
+
+
+## include headers and libraries for Rcpp interface classes
+RCPPINCL := $(shell echo 'Rcpp:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)
+RCPPLIBS := $(shell echo 'Rcpp:::LdFlags()' | $(R_HOME)/bin/R --vanilla --slave)
+
+
+## include headers and libraries for RInside embedding classes
+RINSIDEINCL := $(shell echo 'RInside:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)
+RINSIDELIBS := $(shell echo 'RInside:::LdFlags()' | $(R_HOME)/bin/R --vanilla --slave)
+
+
+## compiler etc settings used in default make rules
+CXX := $(shell $(R_HOME)/bin/R CMD config CXX)
+CPPFLAGS := -Wall $(shell $(R_HOME)/bin/R CMD config CPPFLAGS)
+CXXFLAGS := $(RCPPFLAGS) $(RCPPINCL) $(RINSIDEINCL) $(shell $(R_HOME)/bin/R CMD config CXXFLAGS)
+LDFLAGS = -s
+LDLIBS := $(RLDFLAGS) $(RBLAS) $(RLAPACK) $(RCPPLIBS) $(RINSIDELIBS)
+
+all : $(programs)
+
+clean:
+ rm -vf $(programs)
+
Copied: pkg/inst/examples/standard/Makefile.win (from rev 108, pkg/inst/examples/Makefile.win)
===================================================================
--- pkg/inst/examples/standard/Makefile.win (rev 0)
+++ pkg/inst/examples/standard/Makefile.win 2010-02-19 04:25:56 UTC (rev 109)
@@ -0,0 +1,46 @@
+## -*- mode: makefile; tab-width: 8; -*-
+##
+## Simple Makefile
+##
+## TODO:
+## proper configure for non-Debian file locations, [ Done ]
+## allow RHOME to be set for non-default R etc
+
+## comment this out if you need a different version of R,
+## and set set R_HOME accordingly as an environment variable
+#R_HOME := $(shell R RHOME)
+
+sources := $(wildcard *.cpp)
+programs := $(sources:.cpp=)
+
+
+## include headers and libraries for R
+RCPPFLAGS := $(shell $(R_HOME)/bin/R CMD config --cppflags)
+RLDFLAGS := $(shell $(R_HOME)/bin/R CMD config --ldflags)
+RBLAS := $(shell $(R_HOME)/bin/R CMD config BLAS_LIBS)
+RLAPACK := $(shell $(R_HOME)/bin/R CMD config LAPACK_LIBS)
+
+
+## include headers and libraries for Rcpp interface classes
+RCPPINCL := $(shell echo 'Rcpp:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)
+RCPPLIBS := $(shell echo 'Rcpp:::LdFlags()' | $(R_HOME)/bin/R --vanilla --slave)
+
+
+## include headers and libraries for RInside embedding classes
+RINSIDEINCL := $(shell echo 'RInside:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)
+RINSIDELIBS := $(shell echo 'RInside:::LdFlags()' | $(R_HOME)/bin/R --vanilla --slave)
+
+## compiler etc settings used in default make rules
+CXX := $(shell $(R_HOME)/bin/R CMD config CXX)
+CPPFLAGS := -Wall $(shell $(R_HOME)/bin/R CMD config CPPFLAGS)
+CXXFLAGS := $(RCPPFLAGS) $(RCPPINCL) $(RINSIDEINCL) $(shell $(R_HOME)/bin/R CMD config CXXFLAGS)
+LDFLAGS = -s
+LDLIBS := $(RLDFLAGS) $(RBLAS) $(RLAPACK) $(RCPPLIBS) $(RINSIDELIBS)
+CC := $(shell $(R_HOME)/bin/R CMD config CXX)
+
+
+all : $(programs)
+
+clean:
+ rm -vf $(programs)
+
Copied: pkg/inst/examples/standard/rinside_sample0.cpp (from rev 108, pkg/inst/examples/rinside_sample0.cpp)
===================================================================
--- pkg/inst/examples/standard/rinside_sample0.cpp (rev 0)
+++ pkg/inst/examples/standard/rinside_sample0.cpp 2010-02-19 04:25:56 UTC (rev 109)
@@ -0,0 +1,24 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8; -*-
+//
+// Simple example showing an overly complicated way to do the standard 'hello, world' example
+//
+// Copyright (C) 2009 Dirk Eddelbuettel
+// Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois
+//
+// GPL'ed
+
+#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 txt = "Hello, world!\n";// assign a standard C++ string to 'txt'
+ R["txt"] = txt; // assign C++ string var to R variable 'txt'
+
+ std::string evalstr = "cat(txt)";
+ R.parseEvalQ(evalstr); // eval the init string, ignoring any returns
+
+ exit(0);
+}
+
Copied: pkg/inst/examples/standard/rinside_sample1.cpp (from rev 108, pkg/inst/examples/rinside_sample1.cpp)
===================================================================
--- pkg/inst/examples/standard/rinside_sample1.cpp (rev 0)
+++ pkg/inst/examples/standard/rinside_sample1.cpp 2010-02-19 04:25:56 UTC (rev 109)
@@ -0,0 +1,53 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8; -*-
+//
+// Simple example with data in C++ that is passed to R, processed and a result is extracted
+//
+// Copyright (C) 2009 Dirk Eddelbuettel
+// Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois
+//
+// GPL'ed
+
+#include "RInside.h" // for the embedded R via RInside
+
+std::vector< std::vector< double > >
+createMatrix(const int n) { // simple STL matrix content generator
+ std::vector< std::vector< double > > mat;
+ for (int i=0; i<n; i++) {
+ std::vector<double> row;
+ for (int j=0; j<n; j++) {
+ row.push_back((i*10+j));
+ }
+ mat.push_back(row);
+ }
+ return(mat);
+}
+
+int main(int argc, char *argv[]) {
+ const int mdim = 4;
+ SEXP ans;
+
+ RInside R(argc, argv); // create an embedded R instance
+
+ // create and fill a sample data Matrix
+ std::vector< std::vector< double > > myMatrix = createMatrix(mdim);
+
+ R["M"] = myMatrix; // assign STL matrix to R's 'M' var
+
+ std::string evalstr = "\
+ cat('Running ls()\n'); print(ls()); \
+ cat('Showing M\n'); print(M); \
+ cat('Showing colSums()\n'); Z <- colSums(M); print(Z); \
+ Z"; // returns Z
+
+ R.parseEval(evalstr, ans); // eval the init string -- Z is now in ans
+
+ // convert SEXP ans to a vector of doubles
+ std::vector<double> v = Rcpp::as <std::vector<double> >(ans);
+
+ for (unsigned int i=0; i< v.size(); i++) { // show the result
+ std::cout << "In C++ element " << i << " is " << v[i] << std::endl;
+ }
+ exit(0);
+}
+
+
Copied: pkg/inst/examples/standard/rinside_sample2.cpp (from rev 108, pkg/inst/examples/rinside_sample2.cpp)
===================================================================
--- pkg/inst/examples/standard/rinside_sample2.cpp (rev 0)
+++ pkg/inst/examples/standard/rinside_sample2.cpp 2010-02-19 04:25:56 UTC (rev 109)
@@ -0,0 +1,46 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8; -*-
+//
+// Simple example for the repeated r-devel mails by Abhijit Bera
+//
+// Copyright (C) 2009 Dirk Eddelbuettel 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
+ SEXP ans;
+
+ std::string txt = "suppressMessages(library(fPortfolio))";
+ if (R.parseEvalQ(txt)) // load library, no return value
+ throw std::runtime_error("R cannot evaluate '" + txt + "'");
+
+ txt = "M <- as.matrix(SWX.RET); print(head(M)); M";
+ if (R.parseEval(txt, ans)) // assign matrix M to SEXP variable ans
+ throw std::runtime_error("R cannot evaluate '" + txt + "'");
+ RcppMatrix<double> M(ans); // convert SEXP variable to an RcppMatrix
+
+ std::cout << "M has "
+ << M.getDim1() << " rows and "
+ << M.getDim2() << " cols" << std::endl;
+
+ txt = "colnames(M)";
+ if (R.parseEval(txt, ans)) // assign columns names of M to ans
+ throw std::runtime_error("R cannot evaluate '" + txt + "'");
+ RcppStringVector cnames(ans); // and into string vector cnames
+
+
+ for (int i=0; i<M.getDim2(); i++) {
+ std::cout << "Column " << cnames(i) << " in row 42 has " << M(42,i) << std::endl;
+ }
+
+ } catch(std::exception& ex) {
+ std::cerr << "Exception caught: " << ex.what() << std::endl;
+ } catch(...) {
+ std::cerr << "Unknown exception caught" << std::endl;
+ }
+
+ exit(0);
+}
+
Copied: pkg/inst/examples/standard/rinside_sample3.cpp (from rev 108, pkg/inst/examples/rinside_sample3.cpp)
===================================================================
--- pkg/inst/examples/standard/rinside_sample3.cpp (rev 0)
+++ pkg/inst/examples/standard/rinside_sample3.cpp 2010-02-19 04:25:56 UTC (rev 109)
@@ -0,0 +1,47 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8; -*-
+//
+// Simple example for using lm() using the example from help(swiss)
+//
+// Copyright (C) 2009 Dirk Eddelbuettel and GPL'ed
+
+#include "RInside.h" // for the embedded R via RInside
+#include <iomanip>
+
+int main(int argc, char *argv[]) {
+
+ RInside R(argc, argv); // create an embedded R instance
+ SEXP ans;
+
+ std::string txt = // load library, run regression, create summary
+ "suppressMessages(require(stats));"
+ "swisssum <- summary(lm(Fertility ~ . , data = swiss));"
+ "print(swisssum)";
+ R.parseEvalQ(txt); // eval command, no return
+
+ txt = "swcoef <- coef(swisssum)";
+ R.parseEval(txt, ans); // matrix swisscoef now in SEXP ans
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/rinside -r 109
More information about the Rinside-commits
mailing list