3

I am trying to use a c++ library together with Rcpp and Rstudio. The specific package I am trying to use is CGAL found HERE

I have Rstudio and Rcpp working in Widnows and Linux and I used install instructions from the CGAL pages. In linux it did the installs after adding dependencies. In Windows it installed and created a CGAL_DIR variable set to C:\dev\CGAL-4.11and added C:\dev\CGAL-4.11\auxiliary\gmp\libto my PATH variable, but I have no idea what it added on the linux box.

I have read about adding Boost library How to use Boost library in C++ with Rcpp as well as RcppEigen, but that proved to be simple as I simply installed the package in Rstudio and used // [[Rcpp::depends(BH)]] to use it, but I don't understand why for boost I need the full include path such as #include <boost/math/common_factor.hpp>.

This my basic test code which compiles and runs as long as it has nothing from CGAL.

#include <RcppArmadillo.h>
#include <RcppEigen.h>
#include <Rcpp.h>
#include <RcppCommon.h>
#include <boost/math/common_factor.hpp>
//#include <CGAL/basic.h>
//#include <CGAL/QP_models.h>
//#include <CGAL/QP_functions.h>

// [[Rcpp::depends(RcppEigen)]]
// [[Rcpp::depends(BH)]]
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::depends(RcppEigen)]]

using namespace Rcpp;
using namespace std;
using namespace arma;
using namespace RcppEigen;


using Eigen::Map;
using Eigen::MatrixXd;
using Eigen::VectorXd;
using Eigen::SelfAdjointEigenSolver;

// [[Rcpp::export]]
VectorXd getEigenValues(Map<MatrixXd> M) {
  SelfAdjointEigenSolver<MatrixXd> es(M);
  return es.eigenvalues();
}

// [[Rcpp::export]]
int computeGCD(int a, int b) {
  return boost::math::gcd(a, b);
}

I believe I need to somehow tell the Rtools compiler to find the CGAL libraries. The CGAL page has detailed instructions for Visual Studio, but I don't know how to do that in Rstudio.

I tried copying the CGAL folder into Rtools and RbuildTools folders, which did not help. In Linux I believe the includes are in usr/ or usr/locals but I am less than clueless about how to find out.

All I know about the compiler is that is was from rtools through Rstudio and it works as far as Rcpp goes.

Edit, I found that Rstudio installs packages in: C:\Program Files\R\R-3.3.1\library\ folder and from there each package has a folder and an include folder. In my example, the BH or boost package had no files in the include folder, but it had a boost folder with a bunch of subfolders in it including math which had the common_factor.hpp file.

This explains how the includes work in R so I tried installing CGAL to the Library folder such that it's include folder would be at the next level just as with everything else. However, this did not work. Rcpp::depends cannot load and/or cannot find it.

It seems that R tools or Rstudio does something special when it installs packages that allows them to be used by R and Rcpp. Can anybody tell me how packages are installed so this works?

MichaelE
  • 763
  • 8
  • 22

0 Answers0