For use inside D functions called from R.

Calls into the R API function Rf_error to throw an error if a test condition is not met. Used to stop the R program from running when there is an error in the D code. Without using assertR, there will normally be a segmentation fault and little information about the error. Those are nasty, so you want to add calls to assertR all over your code.

assertR is aliased to enforce, so you can use enforce everywhere (D code calling R or R code calling D functions) if you want.
bool test
string msg


Type: bool

A test for code correctness.

Type: string

The error message to return from R if test is false.


1 // Obviously have mixed up the high and low temperatures
2 int low = 75;
3 int high = 42;
4 assertR(high >= low, "Cannot have the day's high temperature 
5 be less than the day's low temperature");
double[] x = [3.1, 4.7, 1.8];
int ii = 3;
double z = x[ii]; // out of bounds error, will cause a segmentation fault
assertR(ii < x.length, "Index greater than the number of elements");