Skip to content

[Rcpp-devel] Combining C++ interface and exported function name with dot

1 message · Ralf Stubner

#
Hi,

I am developing a package where I would like to combine two Rcpp
Attribute features:
* Automatically providing a C++ interface
* Renaming the exported function in R to contain a dot

My current attempts at doing so result in a run-time error. Steps to
reproduce:

* create an new package with Rcpp::Rcpp.package.skeleton()
* change src/rcpp_hello_world.cpp to rename the exported function and
create both R and C++ interfaces:

// [[Rcpp::interfaces(r, cpp)]]
#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export(hello.world)]]
List rcpp_hello_world() {

    CharacterVector x = CharacterVector::create( "foo", "bar" )  ;
    NumericVector y   = NumericVector::create( 0.0, 1.0 ) ;
    List z            = List::create( x, y ) ;

    return z ;
}

* build and install the package
* reference the function from C++:

// [[Rcpp::depends(anRpackage)]]
#include <Rcpp.h>
#include <anRpackage.h>

// [[Rcpp::export]]
Rcpp::List wrapper() {
  return anRpackage::hello_world();
}
/*** R
wrapper()
*/

If I rename the function to 'hello_world', this compiles and runs fine.
If I rename the function to 'hello.world', it still compiles but fails
to run:
Error in wrapper() :
  Function not exported: C++ function with signature
'List(*hello_world)()' not found in anRpackage.


Is there a way to combine these two features?

Thanks
Ralf