On 15 May 2013 at 20:23, Ivan Popivanov wrote: | Two versions of the code, see at the end. The first converts my std::vectors to | Rcpp equivalents. The second builds the data frame from the std::vectors.
A date.frame is an R list with some special sauce, and it is probably easier to construct this from R types -- reduces temp copies. We can after not (directly) send a std::vector back to R, though the implicit use of wrap() comes close. | Calling the function containing this code numerous times (hundreds if not | thousands) returning the std::vectors directly seems to cause random crashes or | hangs somewhere after the return statement. The other version seems to work | properly. The devil is in the detail. There was some discussion here on the list over the years, and we have one contributed 'faster' data.frame creator here: http://gallery.rcpp.org/articles/faster-data-frame-creation/ Dirk | Thanks, | | return Rcpp::DataFrame::create( | Rcpp::Named("Entry") = Rcpp::IntegerVector(ibeg.begin(), | ibeg.end()), | Rcpp::Named("Exit") = Rcpp::IntegerVector(iendOut.begin | (),iendOut.end()), | Rcpp::Named("Position") = Rcpp::IntegerVector | (position.begin(), position.end()), | Rcpp::Named("StopLoss") = Rcpp::NumericVector | (stopLoss.begin(), stopLoss.end()), | Rcpp::Named("StopTrailing") = Rcpp::NumericVector | (stopTrailing.begin(), stopTrailing.end()), | Rcpp::Named("ProfitTarget") = Rcpp::NumericVector | (profitTarget.begin(), profitTarget.end()), | Rcpp::Named("ExitPrice") = Rcpp::NumericVector | (exitPrice.begin(), exitPrice.end()), | Rcpp::Named("Gain") = Rcpp::NumericVector(gain.begin(), | gain.end()), | Rcpp::Named("MAE") = Rcpp::NumericVector(mae.begin(), | mae.end()), | Rcpp::Named("MFE") = Rcpp::NumericVector(mfe.begin(), | mfe.end()), | Rcpp::Named("Reason") = Rcpp::IntegerVector(reason.begin | (), reason.end())); | /* | return Rcpp::DataFrame::create( | Rcpp::Named("Entry") = ibeg, | Rcpp::Named("Exit") = iendOut, | Rcpp::Named("Position") = position, | Rcpp::Named("StopLoss") = stopLoss, | Rcpp::Named("StopTrailing") = stopTrailing, | Rcpp::Named("ProfitTarget") = profitTarget, | Rcpp::Named("ExitPrice") = exitPrice, | Rcpp::Named("Gain") = gain, | Rcpp::Named("MAE") = mae, | Rcpp::Named("MFE") = mfe, | Rcpp::Named("Reason") = reason); | */ | | ---------------------------------------------------------------------- | _______________________________________________ | Rcpp-devel mailing list | [email protected] | https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel -- Dirk Eddelbuettel | [email protected] | http://dirk.eddelbuettel.com _______________________________________________ Rcpp-devel mailing list [email protected] https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
