RInside Version 0.2.12
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
rinside_sample10.cpp
Go to the documentation of this file.
1 // Simple example motivated by post from Wayne.Zhang@barclayscapital.com
2 // to r-devel on 28 Jan 2011
3 //
4 // Copyright (C) 2011 Dirk Eddelbuettel and Romain Francois
5 
6 #include <RInside.h> // for the embedded R via RInside
7 
8 void show(const Rcpp::List & L) {
9  // this function is cumbersome as we haven't defined << operators
10  std::cout << "Showing list content:\n";
11  std::cout << "L[0] " << Rcpp::as<int>(L[0]) << std::endl;
12  std::cout << "L[1] " << Rcpp::as<double>(L[1]) << std::endl;
13  Rcpp::IntegerVector v = Rcpp::as<Rcpp::IntegerVector>(L[2]);
14  std::cout << "L[2][0] " << v[0] << std::endl;
15  std::cout << "L[2][1] " << v[1] << std::endl;
16 }
17 
18 int main(int argc, char *argv[]) {
19 
20  // create an embedded R instance
21  RInside R(argc, argv);
22 
23  Rcpp::List mylist(3);
24  mylist[0] = 1;
25  mylist[1] = 2.5;
26  Rcpp::IntegerVector v(2); v[0] = 10; v[1] = 11; // with C++0x we could assign directly
27  mylist[2] = v;
28  show(mylist);
29 
30  R["myRlist"] = mylist;
31  std::string r_code = "myRlist[[1]] = 42; myRlist[[2]] = 42.0; myRlist[[3]][2] = 42; myRlist";
32 
33  Rcpp::List reslist = R.parseEval(r_code);
34  show(reslist);
35 
36  exit(0);
37 }
38 
int main(int argc, char *argv[])
int parseEval(const std::string &line, SEXP &ans)
Definition: RInside.cpp:308
void show(const Rcpp::List &L)