RInside Version 0.2.6
inst/examples/standard/rinside_sample11.cpp
Go to the documentation of this file.
00001 // Simple example motivated by post from Paul Smith <phhs80@gmail.com>
00002 // to r-help on 06 Mar 2011
00003 //
00004 // Copyright (C) 2011  Dirk Eddelbuettel and Romain Francois
00005 
00006 #include <RInside.h>                    // for the embedded R via RInside
00007 
00008 int main(int argc, char *argv[]) {
00009 
00010   // create an embedded R instance
00011   RInside R(argc, argv);               
00012 
00013   // evaluate an R expression with curve() 
00014   // because RInside defaults to interactive=false we use a file
00015   std::string cmd = "tmpf <- tempfile('curve'); "  
00016     "png(tmpf); "
00017     "curve(x^2, -10, 10, 200); "
00018     "dev.off();"
00019     "tmpf";
00020   // by running parseEval, we get the last assignment back, here the filename
00021   std::string tmpfile = R.parseEval(cmd);
00022 
00023   std::cout << "Could now use plot in " << tmpfile << std::endl;
00024   unlink(tmpfile.c_str());              // cleaning up
00025 
00026   // alternatively, by forcing a display we can plot to screen
00027   cmd = "x11(); curve(x^2, -10, 10, 200); Sys.sleep(30);";
00028   // parseEvalQ evluates without assignment
00029   R.parseEvalQ(cmd);
00030     
00031   exit(0);
00032 }
00033 
 All Classes Files Functions Variables Enumerations Enumerator Defines