<div dir="ltr"><div><br></div><div>I need to call R adist function over a big vector, many times.</div><div>Internally , adist is calling <a href="https://github.com/SurajGupta/r-source/blob/e242a7ebfb1b9921b29e2c5f88411f5018b0f74f/src/main/agrep.c">adist_full</a> defined in src/main/agrep.c. So wonder If I can call the c function adist_full directly from my c++ code.<br>
</div><div><br></div><div><br></div><div>My workaround is to give adist as a Function parameter. here my code:</div><div><div>#include <Rcpp.h></div><div>using namespace Rcpp;</div><div><br></div><div>// [[Rcpp::export]]<br>
</div><div>List call_adist(CharacterVector y, Function f,int tol=16) {</div><div>    std::vector<std::vector<int> > out;</div><div>    std::vector<std::string> input = as<std::vector<std::string> >(y);</div>
<div>    for (std::vector<std::string>::iterator it = input.begin() ; it != input.end(); ++it){</div><div>      //  can I change f call by adist_full(*it,y,costs,false)?<br></div><div>        std::vector<int> res = as<std::vector<int> >(f(*it,y)); <br>
</div><div><br></div><div>        out.push_back(res);</div><div>    }</div><div>    return Rcpp::wrap(out);</div><div>}<br></div></div><div>Then I call it like :</div><div><br></div><div>    call_adist(vv,adist)<br></div>
<div><div><br></div><div>But this is less efficient than lapply(vv,adist).</div></div><div><br></div><div><span style="color:rgb(68,68,68);font-family:Arial;font-size:14.399999618530273px;line-height:22.399999618530273px">Happy New Year!</span><br>
</div><div><span style="color:rgb(68,68,68);font-family:Arial;font-size:14.399999618530273px;line-height:22.399999618530273px"><br></span></div><div><br></div><div><br></div><div><br></div></div>