Call “multi file C++ code with external libraries referenced” in R

后端 未结 2 551
失恋的感觉
失恋的感觉 2021-01-23 14:12

I have written a code in C++ which uses boost library and also uses multiple files. I am trying to execute the function in R.

Here is my C++ function prototype:

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-23 15:07

    Use Rcpp instead of .Call.

    Add this headers and comment to your .cpp function file:

    #include 
    using namespace Rcpp;
    
    // [[Rcpp::export]]
    

    And now in R:

     install.packages("Rcpp")
     library(Rcpp)
     sourceCpp('path to your .cpp program')
    

    The function EulerInversions should become visible in the environment and you can call it now as any other R function

提交回复
热议问题