2

I'm new to the error-handling in Rcpp. I wonder, how can I stop the error message from showing up in the R console?

Take an example,

In rcpp file:

#include <RcppArmadillo.h>
using namespace arma;

// [[Rcpp::export]]
void chol_c(mat M) {
  try {
    mat S = (chol(M)).t();
    Rcpp::Rcout << S << std::endl;
  } catch(...) {    
    Rcpp::Rcout << "things wrong " << std::endl;
  } 
}

In R:

> mt0=matrix(c(0.5416,  -0.0668 , -0.1538,  -0.2435,
+ -0.0668 ,  0.9836 , -0.0135 , -0.0195,
+ -0.1538 , -0.0135  , 0.0226 ,  0.0334,
+ -0.2435,  -0.0195 ,  0.0334  , 0.0487),4,byrow = T)
> chol_c(mt0)

error: chol(): decomposition failed
things wrong 

My question is how to stop "error: chol(): decomposition failed" from showing up?

My apologies, if the solution is obvious. Thanks!

Ding Li
  • 673
  • 1
  • 7
  • 19
  • 2
    Are they helpful [1](https://stackoverflow.com/questions/19111956/suppress-error-message-in-r) & [2](https://stackoverflow.com/questions/36683031/trycatch-suppress-error-message) ? – user2100721 Jul 29 '18 at 04:01

0 Answers0