How to create instances of S4 classes from R packages in Rcpp code
问题 I'm getting my feet wet with Rcpp trying to create an instance of a sparseMatrix from within Rcpp code. I understand that in order to create S4 objects we call the S4 constructor with the name of the desired class as a string, e.g.: S4 foo() { S4 s("dgCMatrix"); return s; } But in my case this fails with Error in getClass("dgCMatrix") : “dgCMatrix” is not a defined class I assume this is because the Matrix package has not been loaded? I have tried adding // [[Rcpp::depends(Matrix)]] as well