Skip to content
Prev 8423 / 10988 Next

[Rcpp-devel] assert() for Rcpp?

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
think.

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
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?


(Sorry for delay in posting this: the rcpp devel list does not get along
with my mail client.)



Sincerely,

Luke Miratrix
Assistant Professor of Statistics

	Note: Due to my RSI (wrist trouble), e-mail often abrupt.


--

Department of Statistics
Science Center

Harvard University
1 Oxford Street
Cambridge MA 02138-2901


lmiratrix at stat.harvard.edu
510-735-7635
On 2/18/15, 3:25 PM, "Dale Smith" <DSmith at nexidia.com> wrote: