RInside Version 0.2.12
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
rinside_sample7.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 as<>() conversion from Rcpp
4 //
5 // Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois
6 
7 #include <RInside.h> // for the embedded R via RInside
8 
9 int main(int argc, char *argv[]) {
10 
11  try {
12 
13  RInside R(argc, argv); // create an embedded R instance
14  std::string txt;
15 
16  txt = "m <- 1.23";
17  double d1 = Rcpp::as< double >(R.parseEval(txt));
18  std::cout << "d1 " << d1 << std::endl;
19 
20  txt = "M <- 1.0 * 1:6";
21  std::vector<double> d2 = Rcpp::as< std::vector< double > >(R.parseEval(txt));
22  std::cout << "d2[0] " << d2[0] << " d2[1] " << d2[1] << std::endl;
23 
24  } catch(std::exception& ex) {
25  std::cerr << "Exception caught: " << ex.what() << std::endl;
26  } catch(...) {
27  std::cerr << "Unknown exception caught" << std::endl;
28  }
29 
30  exit(0);
31 }
32 
int main(int argc, char *argv[])
int parseEval(const std::string &line, SEXP &ans)
Definition: RInside.cpp:308