Skip to content
Prev 309460 / 398506 Next

R crashing after successfully running compiled code

On Wed, 31 Oct 2012, Duncan Murdoch wrote:

            
Using R-devel and the following new feature

     ? There is a new option, options(CBoundsCheck=), which controls how
       .C() and .Fortran() pass arguments to compiled code.  If true
       (which can be enabled by setting the environment variable
       R_C_BOUNDS_CHECK to yes), raw, integer, double and complex
       arguments are always copied, and checked for writing off either
       end of the array on return from the compiled code (when a second
       copy is made).  This also checks individual elements of character
       vectors passed to .C().

       This is not intended for routine use, but can be very helpful in
       finding segfaults in package code.

makes checking these two points a lot easier.
If you can run your code under valgrind (see 'Writing R Extensions') 
you will usually get pointed to the exact cause.  But that's for 
Linux, and with some care MacOS X.