RInside Version 0.2.12
rinside_sample6.cpp
Go to the documentation of this file.
1 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8; -*-
2 //
3 // Showing off some of the templated conversion due to Rcpp
4 //
5 // Copyright (C) 2009 Dirk Eddelbuettel
6 // Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois
7
8 #include <RInside.h> // for the embedded R via RInside
9
10 int main(int argc, char *argv[]) {
11
12  try {
13
14  RInside R(argc, argv); // create an embedded R instance
15
16  double d1 = 1.234; // scalar double
17  R["d1"] = d1; // or R.assign(d1, "d1")
18
19  std::vector<double> d2; // vector of doubles
20  d2.push_back(1.23);
21  d2.push_back(4.56);
22  R["d2"] = d2; // or R.assign(d2, "d2");
23
24  std::map< std::string, double > d3; // map of doubles
25  d3["a"] = 7.89;
26  d3["b"] = 7.07;
27  R["d3"] = d3; // or R.assign(d3, "d3");
28
29  std::list< double > d4; // list of doubles
30  d4.push_back(1.11);
31  d4.push_back(4.44);
32  R["d4"] = d4; // or R.assign(d4, "d4");
33
34  std::string txt = // now access in R
35  "cat('\nd1=', d1, '\n'); print(class(d1));"
36  "cat('\nd2=\n'); print(d2); print(class(d2));"
37  "cat('\nd3=\n'); print(d3); print(class(d3));"
38  "cat('\nd4=\n'); print(d4); print(class(d4));";
39  R.parseEvalQ(txt);
40
41  } catch(std::exception& ex) {
42  std::cerr << "Exception caught: " << ex.what() << std::endl;
43  } catch(...) {
44  std::cerr << "Unknown exception caught" << std::endl;
45  }
46
47  exit(0);
48 }
49
int main(int argc, char *argv[])
void parseEvalQ(const std::string &line)
Definition: RInside.cpp:366