RInside Version 0.2.12
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
rinside_sample8.cpp
Go to the documentation of this file.
1 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8; -*-
2 //
3 // Simple example showing how to use R[] = ;
4 //
5 // Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois
6 
7 #include <RInside.h> // for the embedded R via RInside
8 
9 int main(int argc, char *argv[]) {
10 
11  RInside R(argc, argv); // create an embedded R instance
12 
13  R["x"] = 10 ; // assignment can be done directly via []
14  R["y"] = 20 ;
15 
16  R.parseEvalQ("z <- x + y") ; // R statement evaluation and result
17  int sum = R["z"]; // retrieval via access using [] and implicit wrapper
18  std::cout << "10 + 20 = " << sum << std::endl ;
19 
20  // we can also return the value directly
21  sum = R.parseEval("x + y") ;
22  std::cout << "10 + 20 = " << sum << std::endl ;
23 
24  exit(0);
25 }
26 
void parseEvalQ(const std::string &line)
Definition: RInside.cpp:366
int parseEval(const std::string &line, SEXP &ans)
Definition: RInside.cpp:308
int main(int argc, char *argv[])