RInside Version 0.2.12
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
rinside_sample11.cpp
Go to the documentation of this file.
1 // Simple example motivated by post from Paul Smith <phhs80@gmail.com>
2 // to r-help on 06 Mar 2011
3 //
4 // Copyright (C) 2011 - 2012 Dirk Eddelbuettel and Romain Francois
5 
6 #include <RInside.h> // for the embedded R via RInside
7 #include <unistd.h>
8 
9 int main(int argc, char *argv[]) {
10 
11  // create an embedded R instance
12  RInside R(argc, argv);
13 
14  // evaluate an R expression with curve()
15  // because RInside defaults to interactive=false we use a file
16  std::string cmd = "tmpf <- tempfile('curve'); "
17  "png(tmpf); "
18  "curve(x^2, -10, 10, 200); "
19  "dev.off();"
20  "tmpf";
21  // by running parseEval, we get the last assignment back, here the filename
22  std::string tmpfile = R.parseEval(cmd);
23 
24  std::cout << "Could now use plot in " << tmpfile << std::endl;
25  unlink(tmpfile.c_str()); // cleaning up
26 
27  // alternatively, by forcing a display we can plot to screen
28  cmd = "x11(); curve(x^2, -10, 10, 200); Sys.sleep(30);";
29  // parseEvalQ evluates without assignment
30  R.parseEvalQ(cmd);
31 
32  exit(0);
33 }
34 
void parseEvalQ(const std::string &line)
Definition: RInside.cpp:366
int main(int argc, char *argv[])
int parseEval(const std::string &line, SEXP &ans)
Definition: RInside.cpp:308