tags:

views:

47

answers:

1

Hi guys,

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 ) ;
}
+1  A: 

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