RInside Version 0.2.6
inst/examples/standard/rinside_sample10.cpp
Go to the documentation of this file.
00001 // Simple example motivated by post from Wayne.Zhang@barclayscapital.com
00002 // to r-devel on 28 Jan 2011
00003 //
00004 // Copyright (C) 2011  Dirk Eddelbuettel and Romain Francois
00005 
00006 #include <RInside.h>                    // for the embedded R via RInside
00007 
00008 void show(const Rcpp::List & L) {
00009     // this function is cumbersome as we haven't defined << operators
00010     std::cout << "Showing list content:\n";
00011     std::cout << "L[0] " << Rcpp::as<int>(L[0]) << std::endl;
00012     std::cout << "L[1] " << Rcpp::as<double>(L[1]) << std::endl;
00013     Rcpp::IntegerVector v = Rcpp::as<Rcpp::IntegerVector>(L[2]);
00014     std::cout << "L[2][0] " << v[0] << std::endl;
00015     std::cout << "L[2][1] " << v[1] << std::endl;
00016 }
00017 
00018 int main(int argc, char *argv[]) {
00019 
00020     // create an embedded R instance
00021     RInside R(argc, argv);               
00022 
00023     Rcpp::List mylist(3);
00024     mylist[0] = 1;
00025     mylist[1] = 2.5;
00026     Rcpp::IntegerVector v(2); v[0] = 10; v[1] = 11; // with C++0x we could assign directly
00027     mylist[2] = v;
00028     show(mylist);
00029 
00030     R["myRlist"] = mylist;
00031     std::string r_code = "myRlist[[1]] = 42; myRlist[[2]] = 42.0; myRlist[[3]][2] = 42; myRlist";
00032     
00033     Rcpp::List reslist = R.parseEval(r_code);
00034     show(reslist);
00035 
00036     exit(0);
00037 }
00038 
 All Classes Files Functions Variables Enumerations Enumerator Defines