How can one extract column labels from an Rcpp::Eigen matrix?
For example, here is some R matrix
mat <- matrix(1:4,ncol=2)
colnames(mat) <- c("col1","col2")
With Rcpp::NumericMatrix, one can simply call colnames like so:
void fun_NM(const Rcpp::NumericMatrixXd& Mat)
{
Rcpp::CharacterVector coln = colnames(Mat);
Rcpp::Rcout << coln << "\n\n";
}
Then fun_NM(mat)
prints "col1" "col2" as it should. Is there a way to access these colnames when the matrix is passes as an Eigen::MatrixXd?
void fun_EM(const Eigen::MatrixXd& Mat)
{
?
}
I don't know how RcppEigen converts the R matrix passed to into the Rcpp code to a Eigen::MatrixXd. Does it first converts it to a Rcpp::NumericMatrix? In that case, one could use Rcpp::NumericMatrix as input, extract the columns, and then transform it to Eigen::MatrixXd manually in the code to use the function in the Eigen library.