RcppEigen sparse matrix insert operation gives invalid class “dgCMatrix” error
问题 I'm trying to get up to speed on using C++ to quickly build some sparse matrices for use in R. However, I cannot seem to use the insert method to change single elements of a sparse matrix in Eigen and get a correct R object of class dgCMatrix. A simple example is below. The C++ code is: #include <RcppEigen.h> // [[Rcpp::depends(RcppEigen)]] using Eigen::SparseMatrix; // sparse matrix // [[Rcpp::export]] SparseMatrix<double> SimpleSparseMatrix(int n) { SparseMatrix<double> new_mat(n, n); new