What follows are just few quick notes hopefully useful to easily debug C functions called from R using the graphical Data Display Debugger running on top of, say, gdb.
Let's assume you have just written a C function to generate a vector of Gaussian random numbers (truncated or not) using the Ratio-Of-Uniforms (ROU) method. If you know nothing about the ROU method and are bothered by that, you can start with the original paper of Kinderman and Monahan (1977) "Computer Generation of Random Variables Using the Ratio of Uniform Deviates" ACM Transactions on Mathematical Software 3: 257-260, or with Josef Leydold (2000) Automatic Sampling with the Ratio-of-uniforms Method ACM Trans. Math. Softw. 26: 78-98. Books and monographs covering the subject include:
Fine, so you have written your functions test_ROU_gogo2 in a file called normROU.c. You now need to generate your object file with the debugging option turned on:
You start R, load your library and call normROU2(10) but something goes wrong!... You might then want to be able to run your C function within a debugger like gdb with the DDD graphical interface.
In order to do that you will have to restart R with some debugging options:

Then from the same menu you will click on Run Again and NOT on run. If everything goes fine an X terminal with a more or less usual R command line appears.

After loading your library into R (dyn.load("rngROU.so")) and your R codes (source("normROU.R")), you select Open Source from the File menu, and then on the pop-up window your code of interest: normROU.c as shown here:

You can now set your break points in the usual way before calling test_gogo_ROU2 from R with something like rnormROU2(10). The execution will stop at your break point and you can enjoy DDD...

Have fun!
Back to C Pouzat Home Page Retour à la page titre de C Pouzat