[Rcpp-devel] Raise a condition

Romain Francois romain at r-enthusiasts.com
Thu Jun 19 00:07:27 CEST 2014


Le 18 juin 2014 à 23:54, Tim Keitt <tkeitt at utexas.edu> a écrit :

> 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?).
> 
> THK

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.  

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 https://github.com/Rcpp11/Rcpp11/blob/450aade7338c16c34618ad0916003e8ca4fb58a6/inst/include/Rcpp/Condition.h

Romain
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20140619/654d2fc0/attachment.html>


More information about the Rcpp-devel mailing list