我正在考虑通过环境从 C++ 调用 R 函数,但出现错误,这就是我所做的
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
NumericVector call(NumericVector x){
Environment env = Environment::global_env();
Function f = env["fivenum"];
NumericVector res = f(x);
return res;
}
Type call(x)
,这就是我得到的,
Error: cannot convert to function
我知道我可以用另一种方式做对
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
NumericVector callFunction(NumericVector x, Function f) {
NumericVector res = f(x);
return res;
}
and type
callFunction(x,fivenum)
但仍然想知道为什么第一种方法失败了。
fivenum https://stat.ethz.ch/R-manual/R-devel/library/stats/html/fivenum.html函数不是在全局环境中定义的,而是在stats
包环境,所以你应该从中获取它:
...
Environment stats("package:stats");
Function f = stats["fivenum"];
...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)