<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Le 19 juin 2014 à 00:15, Tim Keitt <<a href="mailto:tkeitt@utexas.edu">tkeitt@utexas.edu</a>> a écrit :<br><div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr"><br><div class="gmail_extra"><div class="gmail_quote">On Wed, Jun 18, 2014 at 5:07 PM, Romain Francois <span dir="ltr"><<a href="mailto:romain@r-enthusiasts.com" target="_blank">romain@r-enthusiasts.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Le 18 juin 2014 à 23:54, Tim Keitt <<a href="mailto:tkeitt@utexas.edu" target="_blank">tkeitt@utexas.edu</a>> a écrit :<div class="">
<br><div><br><blockquote type="cite"><div dir="ltr">I'd like to raise a condition other than error or warning. Is that possible using the Rcpp api? I assume this can be done via R internals, but I'd prefer not to call error() directly (or is that the recommendation?).<div>
<br></div><div>THK<br clear="all"></div></div></blockquote><br></div></div><div>Definitely not. Rf_error should really only be called from C code. If you call it from C++, there is a great chance you'll lose determinism as destructors for your c++ objects are very likely not to be called. Most of the time, it will just mean you'll never release some objects to the garbage collector, but it could also get you leaks or other nice stuff depending on what your destructors were supposed to do and did not get a chance to do. </div>
</div></blockquote><div><br></div><div>That was my understanding. Just wanted to be sure it was still the case.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><div><br></div><div>I'm not sure Rcpp has a way to raise an R condition apart from calling stop, which usually is good enough. Otherwise, you can borrow from Rcpp11 and adapt some code from <a href="https://github.com/Rcpp11/Rcpp11/blob/450aade7338c16c34618ad0916003e8ca4fb58a6/inst/include/Rcpp/Condition.h" target="_blank">https://github.com/Rcpp11/Rcpp11/blob/450aade7338c16c34618ad0916003e8ca4fb58a6/inst/include/Rcpp/Condition.h</a></div>
</div></blockquote><div><br></div><div>Ah. I see. Eval "stop" in the global env with the condition as the argument. Clever.</div></div></div></div></blockquote><br></div><div>It is more of a hack due to lack of proper api from R. </div><div><br></div><div>If you do this, make sure you don't have any c++ object in scope. Essentially that means you would evaluate `stop( condition )` in a top level catch block. </div></body></html>