<div dir="ltr"><div class="gmail_quote"><div dir="ltr">Hi:<div><br></div><div>I'm trying to call a R function (that compares strings) in Rcpp and return the result to make the comparisons run faster. Am a noob with Rcpp; so please bear. The input to the R function is a matrix of 2 columns. </div><div><br></div><div>The error is: <b>Error in getGoing(product) : Not compatible with STRSXP: [type=NULL]. </b></div><div><br></div><div>Please assist. </div><div><br></div><div>#include<Rcpp.h></div><div>using namespace Rcpp;</div><div><br></div><div>/*** R<br></div><div>comps= function(vec)</div><div>{</div><div> streets <- vec</div><div> cnt <- nrow(streets)</div><div> res <- c()</div><div> print(paste0("Comparing ", (cnt)," pairs..."))</div><div> </div><div> for (i in 1:cnt)</div><div> {</div><div> matched <- TRUE </div><div> prop1 = streets[i,1]</div><div> prop2 = streets[i,2]</div><div><br></div><div> prop1_parts = strsplit(trimws(prop1), ' ')</div><div> prop2_parts = strsplit(trimws(prop2), ' ')</div><div> </div><div> prop1_parts_count = length(prop1_parts[[1]])</div><div> prop2_parts_count = length(prop2_parts[[1]])</div><div> </div><div> if (prop1_parts_count == prop2_parts_count)</div><div> {</div><div> for (x in 1:prop1_parts_count)</div><div> {</div><div> part1 = prop1_parts[[1]][x]</div><div> part2 = prop2_parts[[1]][x]</div><div> </div><div> if (part1 == part2) { </div><div> matched = matched & TRUE </div><div> }</div><div> else if (adist(part1, part2, partial = T)==0 | adist(part2,part1, partial = T)==0){ </div><div> matched = matched & TRUE</div><div> }</div><div> else {</div><div> matched = matched & FALSE</div><div> break</div><div> }</div><div> }#forloop ends</div><div> </div><div> if(matched){</div><div> append(res,paste(prop1,"<-->", prop2))</div><div> }</div><div> }#if loops ends </div><div> }#primary for loops ends</div><div> res</div><div>}#function ends </div><div>*/</div><div><br></div><div>// [[Rcpp::export]]</div><div>Rcpp::StringMatrix getGoing(Rcpp::StringVector vec){</div><div> Rcpp::Environment env = Rcpp::Environment::global_env(<wbr>);</div><div> Rcpp::Function f = env["comps"]; </div><div> Rcpp::StringMatrix result = f(vec);</div><div> return result;</div><div>}</div><div> </div></div>
</div><br></div>