void rowSetParseData(std::vector<char *> rows, Rcpp::DataFrame *resultDataFrame, char *colName, bool isChar) { rapidxml::xml_document<> data; std::string xmlWrapper; char *xmlRow; int textLength; char *parseText; Rcpp::CharacterVector dimension; Rcpp::NumericVector dataColumn; for (int row = 0; row < rows.size(); row++) { bool found = false; xmlWrapper = "<row>"; xmlWrapper = xmlWrapper + rows[row] + "</row>"; xmlRow = strdup(xmlWrapper.c_str()); textLength = strlen(xmlRow); parseText = new char[textLength+1]; parseText = strcpy(parseText, xmlRow); data.parse<0>(parseText); rapidxml::xml_node<char> *rowData = data.first_node()->first_node(colName); if (rowData != NULL) { if (isChar) dimension.push_back(rowData->value()); else dataColumn.push_back(atof(rowData->value())); found = true; } if (!found && isChar) dimension.push_back(NA_STRING); else if (!found && !isChar) dataColumn.push_back(NA_REAL); } if (isChar) resultDataFrame->push_back(dimension); else resultDataFrame->push_back(dataColumn); }
RcppExport SEXP GetPoint(SEXP x,SEXP p,SEXP c) { try { Rcpp::XPtr< flann::Index<flann::L2<float> > > index(x); Rcpp::NumericVector point(p); Rcpp::NumericVector colNum(c); float* indexPoint = index->getPoint(point[0]); Rcpp::NumericVector results; for(int i=0;i<colNum[0];i++) { results.push_back(*(indexPoint+i)); } return results; // -Wall } catch( std::exception &ex ) { // or use END_RCPP macro forward_exception_to_r( ex ); } catch(...) { ::Rf_error( "c++ exception (unknown reason)" ); } return R_NilValue; // -Wall }