c++ - LOAD_RCPP_MODULE 和 Rcpp::InternalFunction 之间的区别

标签 c++ rcpp rinside

在使用 RInside 的上下文中,Rcpp::InternalFunctionLOAD_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/

相关文章:

c++ - "enum class"在 Visual C++ 2012 中是什么意思?

c++ - C/C++ getopt optstring 语法

c - 带有 C/C++ 和 openMP 的 R 包 : how to make "Makevars" file under "mypackage/src/" folder?

c++ - 如何在 Rcpp 函数中更改 R 结构的值

c++ - 在 Windows 中将 rinside 与 qt 一起使用

oop - 将 RInside 的 'R' 实例作为类/方法之间的参数传递

c++ - RInside 段错误和链接问题

c++ - C++ 中的 clr 托管 - 程序集路径

c++ - 带有像素图图像的 QLabel 变得模糊

r - 如何在 R 中得到一个大的稀疏矩阵? (> 2^31-1)