时间:2010-07-25 01:56:15

标签: c++ rcpp

1 个答案:

答案 0 :(得分:2)

要从外部库(“yada.dll”)加载模块,必须为Module()函数提供PACKAGE参数:

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

完整示例如下所示(在Linux下测试,我猜它在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" )