RInside Version 0.2.12
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
rinside_sample12.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 // Simple example motivated by StackOverflow question on using sample() from C
4 //
5 // Copyright (C) 2012 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  std::string cmd = "set.seed(123); sample(LETTERS[1:5], 10, replace=TRUE)";
14 
15  Rcpp::CharacterVector res = R.parseEval(cmd); // parse, eval + return result
16 
17  for (int i=0; i<res.size(); i++) { // loop over vector and output
18  std::cout << res[i];
19  }
20  std::cout << std::endl;
21 
22  std::copy(res.begin(), res.end(), // or use STL iterators
23  std::ostream_iterator<char*>(std::cout));
24  std::cout << std::endl;
25 
26  exit(0);
27 }
28 
int main(int argc, char *argv[])
int parseEval(const std::string &line, SEXP &ans)
Definition: RInside.cpp:308