Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Rcpp find a new module?

Tags:

c++

rcpp

After I successfully compiled a new Rcpp module (the example from "Exposing C++ functions and classes with Rcpp modules, Dirk Eddelbuettel Romain Francois")

Following the instructions in the paper,

require( Rcpp )
yada <- Module( "yada" )

R complained about errors:

Error in FUN("_rcpp_module_boot_yada"[[1L]], ...) : 
    no such symbol _rcpp_module_boot_yada in package .GlobalEnv

I tried putting ''dyn.load("/path/to/yada.dll")'' before calling ''Module( "yada" )'', still the same error.

There is very little info about the Rcpp's Module online. Does any known how to solve the problem? Should I put compiled module dll in some specifiec folder?

The example code:

const char* hello( std::string who ){
  std::string result( "hello " ) ;
  result += who ;
  return result.c_str() ;
}

RCPP_MODULE(yada){
  using namespace Rcpp ;
  function( "hello", &hello ) ;
}
like image 995
Milo Avatar asked Nov 06 '22 10:11

Milo


1 Answers

To load the module from the external library ("yada.dll"), you must provide the PACKAGE argument to the Module() function:

yada <- Module( "yada", PACKAGE = "yada" )

The complete example looks as follows (tested under Linux, I guess it works analogous under Windows):

C++:

#include <Rcpp.h>

const char* hello( std::string who ){
  std::string result( "hello " ) ;
  result += who ;
  return result.c_str() ;
}

RCPP_MODULE(yada){
  using namespace Rcpp ;
  function( "hello", &hello ) ;
}

R:

require( Rcpp )
dyn.load( "yada.so" )
yada <- Module( "yada", PACKAGE = "yada" )
yada$hello( "world" )
like image 158
user404372 Avatar answered Nov 11 '22 03:11

user404372