Hello, I am trying to return a matrix derived from a std::vector<bool> with row names.
I followed the advice of Kevin and Dirk I read at https://stackoverflow.com/questions/19864226/convert-stdvector-to-rcpp-matrix Strangely, the matrix is correct, but when I print it in R, it prints differently to defining it in R: #include <Rcpp.h> #include <string> // [[Rcpp::export]] SEXP make_mat(std::vector<bool> x, std::vector<std::string> n, int nrow, int ncol) { Rcpp::LogicalVector y = Rcpp::wrap(x); y.attr("dim") = Rcpp::Dimension(nrow, ncol); y.attr(".Dimnames") = Rcpp::List::create(n, R_NilValue); return y; } rcpp_mat <- make_mat(c(T,T,F,F), c("a", "b"), 2, 2) rcpp_mat [,1] [,2] [1,] TRUE FALSE [2,] TRUE FALSE attr(,".Dimnames") attr(,".Dimnames")[[1]] [1] "a" "b" attr(,".Dimnames")[[2]] NULL rmat [,1] [,2] a TRUE FALSE b TRUE FALSE > typeof(rmat) [1] "logical" > typeof(rcpp_mat) [1] "logical" > class(rmat) [1] "matrix" > class(rcpp_mat) [1] "matrix" identical(rmat, rcpp_mat) [1] FALSE What's going on here, please? Ideally, I'd rather construct a LogicalMatrix directly from std::vector<bool>, but I don't think you have that constructor. Thanks, Jack. _______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel