On 11 August 2015 at 12:30, Florian Plaza Oñate wrote: | Hi everyone, | | I am trying to copy the rownames and the colnames from a NumericMatrix | to another NumericMatrix by using Rcpp | | Here is my code: | | Rcpp::NumericMatrix copy(const Rcpp::NumericMatrix& m) | { | Rcpp::NumericMatrix m2(num_genes, num_samples); | Rcpp::rownames(m2) = Rcpp::rownames(m); | Rcpp::colnames(m2) = Rcpp::colnames(m);
If you want a full copy, try Rcpp::NumericMatrix m2 = Rcpp::clone(m); as in R> cppFunction("NumericMatrix foo(NumericMatrix m) { return Rcpp::clone(m); }"); R> m <- matrix(1:4,2,2,TRUE,list(c("a","b"), c("c", "d"))) R> foo(m) c d a 1 2 b 3 4 R> | return m2; | } | | It does change the default rownames and colnames of the NumericMatrix. | Do you know how to do it? Now I am confused. You do want to change them or not? If you do _not_ use clone(), then m2 and m share the same underlying pointer. This has been explained before: we use proxy objects which are more lightweight. Distinct copies require clone(). Dirk -- http://dirk.eddelbuettel.com | @eddelbuettel | e...@debian.org _______________________________________________ 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