[Rcpp-devel] call R internal adist function from Rcpp

contact AG STUDY contact at ag-study.com
Mon Dec 30 19:26:44 CET 2013


I need to call R adist function over a big vector, many times.
Internally , adist is calling
adist_full<https://github.com/SurajGupta/r-source/blob/e242a7ebfb1b9921b29e2c5f88411f5018b0f74f/src/main/agrep.c>
defined
in src/main/agrep.c. So wonder If I can call the c function adist_full
directly from my c++ code.


My workaround is to give adist as a Function parameter. here my code:
#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export]]
List call_adist(CharacterVector y, Function f,int tol=16) {
    std::vector<std::vector<int> > out;
    std::vector<std::string> input = as<std::vector<std::string> >(y);
    for (std::vector<std::string>::iterator it = input.begin() ; it !=
input.end(); ++it){
      //  can I change f call by adist_full(*it,y,costs,false)?
        std::vector<int> res = as<std::vector<int> >(f(*it,y));

        out.push_back(res);
    }
    return Rcpp::wrap(out);
}
Then I call it like :

    call_adist(vv,adist)

But this is less efficient than lapply(vv,adist).

Happy New Year!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20131230/8218b21b/attachment.html>


More information about the Rcpp-devel mailing list