[Rcpp-devel] assert() for Rcpp?
edd at debian.org
Tue Feb 24 19:59:32 CET 2015
On 24 February 2015 at 15:45, Miratrix, Luke wrote:
| As an inexperienced person myself, I was trying to wrap a C++ stand-alone
| package so it could be called from R and was trying to preserve some of
| the safety features and error-checking. My understanding of asserts is
| they are to catch disasters that indicate bugs in the code itself, and are
| thus distinct from normal exceptions. They therefore print out the failed
| check and a line-number in the source file and bail.
| When using Rcpp, I came up against CRAN¹s admonition to not print to
| stderr and so couldn¹t use assert() and stay ³legal.² But I found this
| out only after annoying people by not doing what I was supposed to do.
| Given that, having assert() redefined so it is compliant with CRAN and
| plays nice with R, but also maintains its behavior would be pretty cool, I
| All this being said, Nathan Kurz¹s comments also seem good except I think
| it is ³illegal² to print to STDERR directly before aborting, since it is
You are allowed to use Rcpp::Cerr which redirects into R's error stream.
| only aborting the C++ part, and not the entire R session. Hence my hack
| of printing to a string buffer and then handing it to the Rf_error call.
| I don¹t know the guts of Rf_error, but I had assumed it would copy the
| string to its own world before unwinding the stack. If it doesn¹t then I
| agree this is going to cause problems. What is the correct way to pass a
| message up, then?
You are close. We are doing similar things with exceptions we catch; we
create a string and pass it to Rf_errror.
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
More information about the Rcpp-devel