RInside Version 0.2.12
rinside_eigen1.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 Eigen classes on matrix data generated in R
4 //
5 // Copyright (C) 2012 Dirk Eddelbuettel and Romain Francois
6
7 #include <RInside.h> // for the embedded R via RInside
8 #include <RcppEigen.h>
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  const Eigen::Map<Eigen::MatrixXd> m = // parse, eval + return result
17  Rcpp::as<Eigen::Map<Eigen::MatrixXd> >(R.parseEval(cmd));
18  Eigen::MatrixXd n = m.transpose() * m;
19  Eigen::ColPivHouseholderQR<Eigen::MatrixXd> nqr(n);
20
21  std::cout << "Initial Matrix m\n" << m << std::endl;
22  std::cout << "Product n = m' * m\n" << n << std::endl;
23  std::cout << "n.sum() " << n.sum() << std::endl;
24  std::cout << "nrq.rank() " << nqr.rank() << std::endl;
25
26  exit(0);
27 }
int main(int argc, char *argv[])
int parseEval(const std::string &line, SEXP &ans)
Definition: RInside.cpp:308