RInside Version 0.2.10
inst/examples/standard/rinside_sample7.cpp
Go to the documentation of this file.
00001 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4;  tab-width: 8; -*-
00002 //
00003 // Showing off some of the templated as<>() conversion from Rcpp
00004 //
00005 // Copyright (C) 2010 - 2011  Dirk Eddelbuettel and Romain Francois
00006 
00007 #include <RInside.h>                    // for the embedded R via RInside
00008 
00009 int main(int argc, char *argv[]) {
00010 
00011     try {
00012 
00013         RInside R(argc, argv);          // create an embedded R instance 
00014         std::string txt;
00015 
00016         txt = "m <- 1.23";
00017         double d1 = Rcpp::as< double >(R.parseEval(txt));
00018         std::cout << "d1 " << d1 << std::endl;
00019 
00020         txt = "M <- 1.0 * 1:6";
00021         std::vector<double> d2 = Rcpp::as< std::vector< double > >(R.parseEval(txt));
00022         std::cout << "d2[0] " << d2[0] << " d2[1] " << d2[1] << std::endl;
00023         
00024     } catch(std::exception& ex) {
00025         std::cerr << "Exception caught: " << ex.what() << std::endl;
00026     } catch(...) {
00027         std::cerr << "Unknown exception caught" << std::endl;
00028     }
00029 
00030     exit(0);
00031 }
00032 
 All Classes Files Functions Variables Enumerations Enumerator Defines