【发布时间】:2015-04-06 00:16:22
【问题描述】:
我有一个关于通过 Rcpp 在 R 中集成 C++ 的非常基本的问题。假设我想在 C++ 中实现一个像这样的简单函数:
inte = function(x, y, a, b){
model = approxfun(x, y)
return(integrate(model, a, b)$value)
}
所以一个非常基本的方法是尽可能多地调用 R 的函数“集成”:
// [[Rcpp::export]]
double intecxx(Function inte, NumericVector x, NumericVector y,
double a, double b) {
NumericVector res;
res = inte(x, y, a, b);
return res[0];
}
但是,我需要在我的 C++ 代码的许多其他部分中使用这个“intecxx”,因此从其他地方调用它会导致“inte”在范围内不可用。任何帮助表示赞赏。
【问题讨论】: