c++rcpprinside

difference between LOAD_RCPP_MODULE and Rcpp::InternalFunction


What is the difference between Rcpp::InternalFunction and LOAD_RCPP_MODULE in the context of using RInside? They seem to have the same purpose just LOAD_RCPP_MODULE has an extra layer. What are the use cases for both of them and when should i prefer one over the other?

//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);

Here is the other example

//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 )

Solution

  • Modules would let you expose several functions and classes. InternalFunction only exposes one function at a time.

    InternalFunction is something of a curiosity, that we added at some point to answer a "can we do that" type of question. It is one of these things that stay in Rcpp because they once were, but that does not get too much attention from us. It is mostly used in RInside to allow R code to call c++ functions. This is a curious pattern given that with RInside the focus is a C++ application embedding R.

    Modules however, do get a lot of attention. My advice would be to use them.