RInside Version 0.2.12
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
rinside_arma1.cpp
Go to the documentation of this file.
1 // -*- c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 //
3 // Simple example using Armadillo on matrix data generated in R
4 //
5 // Copyright (C) 2012 - 2013 Dirk Eddelbuettel and Romain Francois
6 
7 #include <RcppArmadillo.h> // for Armadillo as well as Rcpp
8 #include <RInside.h> // for the embedded R via RInside
9 
10 int main(int argc, char *argv[]) {
11 
12  RInside R(argc, argv); // create an embedded R instance
13 
14  std::string cmd = "set.seed(42); matrix(rnorm(9),3,3)"; // create a random Matrix in r
15 
16  arma::mat m = Rcpp::as<arma::mat>(R.parseEval(cmd)); // parse, eval + return result
17  arma::mat n = m.t() * m;
18  double nacc = arma::accu(n);
19  double nrnk = arma::rank(n);
20 
21  m.print("Initial Matrix m"); // initial random matrix
22  n.print("Product n = m' * m"); // product of m' * m
23  std::cout << "accu(n) " << nacc << " "
24  << "rank(n) " << nrnk << std::endl; // accu() and rank()
25 
26  exit(0);
27 }
28 
int parseEval(const std::string &line, SEXP &ans)
Definition: RInside.cpp:308
int main(int argc, char *argv[])