Best way to use c++ code from R package FOO in package BAR

后端 未结 3 753
星月不相逢
星月不相逢 2021-02-06 01:20

I am trying to define a function using Rcpp for speedup. The situation is as follows:

  • I have a package FOO with a lot of C++ code (my own package and currently not
3条回答
  •  面向向阳花
    2021-02-06 02:00

    Another option, in case you don't mind introducing Rcpp into package FOO - follow along with Section 3.5 of Rcpp-attributes and do the following:

    1. Place // [[Rcpp::interfaces(cpp)]] at the top of the .cpp source files containing functions you'd like to be made available to other packages,

    2. Place // [[Rcpp::export]] in front of those functions you would like exported,

    3. Call compileAttributes() in the package directory of FOO to generate files in inst/include that can then be used by package BAR, using // [[Rcpp::depends(FOO)]],

    4. Install package FOO.

    If you have this set up correctly, you should be able to call a function with a template like this (supposing foo_a is an exported function from FOO):

    // [[Rcpp::depends(FOO)]]
    
    #include 
    #include 
    using namespace Rcpp;
    
    // [[Rcpp::export]]
    SEXP some_function() {
      return FOO::foo_a();
    }
    

提交回复
热议问题