In #1451 @cgiachalis suggested an Armadillo variant using a lambda which got us riffing a little. As shown in the (final ?) example, if we just enhance the existing Nullable::as() a little we can make this really right:
// [[Rcpp::export]]
arma::mat bis(Rcpp::Nullable<arma::mat> m = R_NilValue) {
return (m.isNotNull() ? m.as() : arma::mat{0,0, arma::fill::none});
}
This utilizes a 'thirteen char' addition we should add.
modified inst/include/Rcpp/Nullable.h
@@ -126,7 +126,7 @@ namespace Rcpp {
/**
* Returns m_sexp as a T
*/
- inline T as() { return get(); }
+ inline T as() { return Rcpp::as<T>(get()); }
/**
* Return a clone of m_sexp as a T
In #1451 @cgiachalis suggested an Armadillo variant using a lambda which got us riffing a little. As shown in the (final ?) example, if we just enhance the existing
Nullable::as()a little we can make this really right:This utilizes a 'thirteen char' addition we should add.