在使用 RInside 的上下文中,Rcpp::InternalFunction
和 LOAD_RCPP_MODULE
有什么区别?它们似乎具有相同的目的,只是 LOAD_RCPP_MODULE
多了一层。它们的用例是什么?我什么时候应该更喜欢一个?
//example with LOAD_RCPP_MODULE
const char* hello( std::string who ){
std::string result( "hello " ) ;
result += who ;
return result.c_str() ;
}
RCPP_MODULE(bling){
using namespace Rcpp ;
function( "hello", &hello );
}
R["bling"] = LOAD_RCPP_MODULE(bling);
这是另一个例子
//example with Rcpp::InternalFunction
const char* hello( std::string who ){
std::string result( "hello " ) ;
result += who ;
return result.c_str() ;
}
R["hello"] = Rcpp::InternalFunction( &hello )
最佳答案
模块可以让您公开多个函数和类。 InternalFunction
一次只公开一个函数。
InternalFunction
是一种好奇心,我们在某个时候添加它来回答“我们能做到吗”类型的问题。这是留在 Rcpp 中的其中一件事,因为它们曾经是,但我们并没有太多关注。主要用在RInside
中,让R代码调用c++函数。这是一个奇怪的模式,因为 RInside
的重点是嵌入 R 的 C++ 应用程序。
然而,模块确实得到了很多关注。我的建议是使用它们。
关于c++ - LOAD_RCPP_MODULE 和 Rcpp::InternalFunction 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18552308/