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

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


Dirk,

So either or :

   - I copy adist_full code source (not really familiar but I ll give it a
   try)
   - Or easier solution , I'll explore levenshteiSim function from
RecordLinkage
   <http://cran.r-project.org/web/packages/RecordLinkage/index.html>package.


Thanks.



On Mon, Dec 30, 2013 at 7:33 PM, Dirk Eddelbuettel <edd at debian.org> wrote:

>
> Amine,
>
> On 30 December 2013 at 19:26, contact AG STUDY wrote:
> | I need to call R adist function over a big vector, many times.
> | Internally , adist is calling adist_full defined in src/main/agrep.c. So
> | wonder If I can call the c function adist_full directly from my c++ code.
>
> You may need to reimplement the adist_full() function in your own package.
> You can start by copying it and then figuring out one-by-one what the
> dependencies are, and satisfy those.
>
> I am not so familiar with the NPL and text regression fields, but similar
> functionality may be available somewhere else too.
>
> | 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));
>
> This will indeed not be fast as you call out to R each time. You would need
> this functionality as C/C++ code.
>
> Dirk
>
>
> |         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!
> |
> |
> |
> |
> |
> | ----------------------------------------------------------------------
> | _______________________________________________
> | Rcpp-devel mailing list
> | Rcpp-devel at lists.r-forge.r-project.org
> | https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
> --
> Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20131230/222559ab/attachment.html>


More information about the Rcpp-devel mailing list