我正在尝试通过以下方式将 boost 包包含在 Rcpp 文件中:
#include <boost/math/distributions/binomial.hpp>
由于安装在高性能计算集群的路由下,所以我将路由改为:
#include "/storage/icds/RISE/sw8/boost_1_81_0/boost/math/distributions/binomial.hpp"
但是,在
binomial.hpp
中,还有其他hpp文件,我无权更改其路线,所以我未能包含binomial.hpp
。
我有办法包含包裹吗?
您最好将 CRAN 包 BH 与 Rcpp 一起使用。有关示例,请参阅 Rcpp Gallery 站点。
这是一个简单的例子
你可以
Rcpp::sourceCpp(filename_here)
它。
// [[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()
*/
当然请注意,您还可以通过 Rcpp 从 R 获取二项式。这也记录在Rcpp Gallery。