I have a cpp file which contains the code as below:
#include <RcppEigen.h>
//[[Rcpp::depends(RcppEigen)]]
using namespace Eigen;
//[[Rcpp::export]]
Eigen::VectorXd memory(const double u, const double v, const double w){
Eigen::VectorXd A(3);
A << u,v,w;
return(A);
}
But it shows me this error in the command (Please see the attached screenshot).
The whole R session ABORTS because of this. Why this is happening? Can anyone help? How can I write this numeric vector properly?
Rcpp and RcppEigen are glue packages and may have a side effect on existing components. So the
<<
idiom used to assign a matrix may be in the Eigen docs but may get shadowed by the Rcpp input/output ops.In another note, your title is a little off. This does not 'write', you were trying to assign. Which ... you can do more easily from R directly as in this example:
which we can call from R and have the bottom portioned executed if we just call
Rcpp::sourceCpp()
on it: