// -*- Mode:C++; Coding:us-ascii-unix; fill-column:160 -*-
/**************************************************************************************************************************************************************/
/**
@file      riVariables.cpp
@author    Mitch Richling <https://www.mitchr.me>
@Copyright Copyright 2015 by Mitch Richling.  All rights reserved.
@date      2015-MM-DD
@brief     How to set R variables from C++ variable values, and how to set C++ variables with R variable values.@EOL
@Keywords  rinside examples r cran package c++ hello world
@Std       C++11

In addition to 1 element R vectors demonstrated ('a' & 'b'), R vectors can be created with standard containers too:
  - std::vector<double> d2 = {3.1415, 6.2831};
  - std::list<double> d4 = {3.1415, 6.2831};
  - std::map<std::string, double> d3 = { { "p", 3.1415 }, {"2p", 3.1415} };
    In this case the map keys become the 'names' attribute of the R vector
*/

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include <RInside.h>                                                     /* RInside                 R pkg    */

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main(int argc, char *argv[]) {

  RInside R(argc, argv);                        // create an embedded R instance

  R["a"] = 3.141592653;                         // Set the R variable 'a' with a C++ literal

  int b = 3;
  
  R["b"] = b;                                   // Set the R variable 'b' to the value in the C++ variable of the same name.

  R.parseEvalQ("c <- a + b");                   // Have R create a variable 'c' from a computation

  double c = R["c"];                            // Get the value of the R variable 'c' and put it in a C++ variable of the same name
  
  std::cout << "a+b = " << c << std::endl ;

  exit(0);
}