<div>Thanks for the reply.</div><div><br></div><div>I tried the following:</div><div><br></div><div>#########################################################</div><div><div>RcppExport SEXP foo( SEXP X, SEXP Y) {</div><div>

<span class="Apple-tab-span" style="white-space:pre"> </span>try {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>arma::mat x=Rcpp::as<arma::mat>(X), y=Rcpp::as<arma::mat>(Y);</div><div>

<span class="Apple-tab-span" style="white-space:pre">         </span>arma::mat output;</div><div><span class="Apple-tab-span" style="white-space:pre">            </span>output = arma::solve( x, y );</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>return(wrap( output) );</div>

<div><span class="Apple-tab-span" style="white-space:pre">      </span>} catch( std::exception& __ex__ ) {</div><div><span class="Apple-tab-span" style="white-space:pre">              </span>::Rf_error( "System is computationally singular" );</div>

<div><span class="Apple-tab-span" style="white-space:pre">              </span>//forward_exception_to_r( __ex__ );</div><div><span class="Apple-tab-span" style="white-space:pre">  </span>} catch(...) {</div><div><span class="Apple-tab-span" style="white-space:pre">               </span>::Rf_error( "c++ exception (unknown reason)" );</div>

<div><span class="Apple-tab-span" style="white-space:pre">      </span>}</div><div>}</div><div>#########################################################</div></div><div><br></div><div><br></div><div>This would give me the message below. I wonder if there is any way to suppress the error message generated by Armadillo (" error: solve(): solution not found") and only output the custom error message (e.g., "Error: System is computationally singular").  Or conversely, is it possible to only show the error message thrown by Armadillo? Thanks.</div>

<div><br></div><div> </div><div><div>##########################################</div><div><br></div><div>> m = cbind(1:2, 1:2)</div><div><div>> m</div><div>     [,1] [,2]</div><div>[1,]    1    1</div><div>[2,]    2    2</div>

<div><br></div><div>> .Call("foo", m, m)</div><div><br></div><div>error: solve(): solution not found</div><div><br></div><div>Error: System is computationally singular</div></div></div><div><br></div><div>##########################################</div>

<div><br></div>

<div><br></div><div><br></div><div><br><br><div class="gmail_quote">On Sat, Jul 6, 2013 at 9:28 PM, Dirk Eddelbuettel <span dir="ltr"><<a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a>></span> wrote:<br>



<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><br>
On 6 July 2013 at 18:56, Xiao He wrote:<br>
| Hi dear listers,<br>
|<br>
| Take the mock function below for an example. What would be the best way to<br>
| handle computational singularity?<br>
<br>
</div>That is essentially a _statistical_ issue and not a Rcpp problem so that is<br>
not really the right forum.<br>
<div><br>
| #include <R.h><br>
| #include <stdio.h><br>
| #include <RcppArmadillo.h><br>
| // [[Rcpp::depends(RcppArmadillo)]]<br>
|<br>
| using namespace Rcpp;<br>
| using namespace arma;<br>
|<br>
| RcppExport SEXP foo(SEXP X, SEXP Y){<br>
| arma::mat x=Rcpp::as<arma::mat>(X), y=Rcpp::as<arma::mat>(Y);<br>
| arma::mat output = arma::solve(x, y );<br>
| return(wrap(output));<br>
| }<br>
|<br>
|<br>
| For instance, if I use the function on the dataset below, R would crash. I read<br>
| the error handling section of the document in <a href="http://www.jstatsoft.org/v40/i08/" target="_blank">http://www.jstatsoft.org/v40/i08/</a><br>
| paper, but I am not exactly sure what to do with my situation. Thank you in<br>
<br>
</div>Rcpp offers support for exception handling -- meaning that _you_ could decide<br>
to throw an exception to signal to the user that his data is not right /<br>
properly conditioned.<br>
<br>
See the Armadillo documentation to learn how to test rank of matrices<br>
etc. You may also learn that sole() is for a matrix and a vector, not two<br>
vectors.<br>
<br>
Dirk<br>
<div><br>
<br>
| advance for your help!<br>
|<br>
| x = cbind(1:2, 1:2)<br>
| .Call("foo", x, x)<br>
|<br>
|<br>
|<br>
</div>| ----------------------------------------------------------------------<br>
| _______________________________________________<br>
| Rcpp-devel mailing list<br>
| <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">Rcpp-devel@lists.r-forge.r-project.org</a><br>
| <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
<span><font color="#888888">--<br>
Dirk Eddelbuettel | <a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a> | <a href="http://dirk.eddelbuettel.com" target="_blank">http://dirk.eddelbuettel.com</a><br>
</font></span></blockquote></div><br></div>