In Rcpp, how to include cpp package that installed in cluster?

37 Views Asked by At

I am trying to include the boost package in Rcpp file by:

#include <boost/math/distributions/binomial.hpp>

Since it is installed under the route of a high performance computing cluster, so I change the route to:

#include "/storage/icds/RISE/sw8/boost_1_81_0/boost/math/distributions/binomial.hpp"

However, within the binomial.hpp, there are other hpp files that I don't have the permission to alter their routes, so I failed to include the binomial.hpp.

Is there a way for me to include the package?

1

There are 1 best solutions below

0
Ada Lovelace On BEST ANSWER

You are better off using the CRAN package BH together with Rcpp. See the Rcpp Gallery site for examples.

Here is a simple example that

  • accesses the header you list for the Binomial
  • show the first few lines of the Boost example for it
  • keeping it simple with no returns etc

You can Rcpp::sourceCpp(filename_here) it.

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

#include <boost/math/distributions/binomial.hpp>
using boost::math::binomial;

#include <Rcpp/Lighter>

// [[Rcpp::export]]
void mybinom(double success_fraction = 0.5, int flips = 10) {
    Rcpp::Rcout << "Using Binomial distribution to predict how many heads and tails." << std::endl;

    binomial flip(flips, success_fraction);

    Rcpp::Rcout << "From " << flips << " one can expect to get on average "
                << mean(flip) << " heads (or tails)." << std::endl
                << "Mode is " << mode(flip) << std::endl
                << "Standard deviation is " << standard_deviation(flip) << std::endl
                << "So about 2/3 will lie within 1 standard deviation and get between "
                <<  ceil(mean(flip) - standard_deviation(flip))  << " and "
                << floor(mean(flip) + standard_deviation(flip)) << " correct." << std::endl
                << "Skewness is " << skewness(flip) << std::endl;
}

/*** R
mybinom()
*/

Note, of course, that you can also get Binomial from R via Rcpp. That is also documented at the Rcpp Gallery.