[R] Ways to understand C code (like debug function)

Justin Thong justinthong93 at gmail.com
Mon Aug 1 18:01:37 CEST 2016


Hi

I need some advice. Note: I do not know anything from C apart from my 2
days of research.

I am currently trying to make meaning of the modelmatrix function (written
in C) and called from R function model.matrix() via .External2.

In trying to view the source code (in R) for model.matrix(), I have been
reasonably succesful thanks to the debug command. This command was good
because I was able to check line-by-line what the code was doing and obtain
an output within my R console. Furthermore, checking the values of each of
my variables while sequentially moving through the lines was also very
useful. However, just by looking at the R source code, it is insufficient
in understanding most of the computation. I have to look within the C code.
In particular, within model.matrix(), a .External2 call is executed to a C
function named modelmatrix. I downloaded the source from the website and
can view the function modelmatrix(in model.c) in a text editor. I am now
finding a way to play with the code so I understand whats going on and I
don't know what's the best way to do this.

I* was wondering whether there is an equivalent way as the debug function
to check C code line by line. ie each line of code are typed in, and an
output is obtained*. I know a package "inline" allows you to build C
functions and use them in R. But I can't find anything which does what I
want. * If this is not possible, is there an alternative good, easy way to
run through and understand the commands in C that anyone knows about.*

-- 
Yours sincerely,
Justin

*I check my email at 9AM and 4PM everyday*
*If you have an EMERGENCY, contact me at +447938674419(UK) or
+60125056192(Malaysia)*

	[[alternative HTML version deleted]]



More information about the R-help mailing list