[Rcpp-devel] Is creating a DataFrame from std::vector-s supposed to work?
Ivan Popivanov
ivan.popivanov at gmail.com
Thu May 16 02:23:01 CEST 2013
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.
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.
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);
*/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20130515/2c5aa53a/attachment.html>
More information about the Rcpp-devel
mailing list