RInside Version 0.2.12
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
rinside_sample15.cpp
Go to the documentation of this file.
1 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 //
3 // Creating a lattice plot from RInside
4 // cf http://stackoverflow.com/questions/24378223/saving-lattice-plots-with-rinside-and-rcpp/
5 //
6 // Copyright (C) 2014 Dirk Eddelbuettel and GPL'ed
7 
8 #include <RInside.h> // for the embedded R via RInside
9 #include <unistd.h>
10 
11 int main(int argc, char *argv[]) {
12 
13  // create an embedded R instance
14  RInside R(argc, argv);
15 
16  // evaluate an R expression with curve()
17  // because RInside defaults to interactive=false we use a file
18  std::string cmd = "library(lattice); "
19  "tmpf <- tempfile('xyplot', fileext='.png'); "
20  "png(tmpf); "
21  "print(xyplot(Girth ~ Height | equal.count(Volume), data=trees)); "
22  "dev.off();"
23  "tmpf";
24 
25  // by running parseEval, we get the last assignment back, here the filename
26  std::string tmpfile = R.parseEval(cmd);
27  std::cout << "Can now use plot in " << tmpfile << std::endl;
28 
29  exit(0);
30 }
31 
int parseEval(const std::string &line, SEXP &ans)
Definition: RInside.cpp:308
int main(int argc, char *argv[])