SEXP returnRealIfPossible(Eigen::MatrixBase<Derived> &matvec) { SEXP result; if(matvec.imag().isZero()) result = wrap(matvec.real()); else result = wrap(matvec); return result; }