[R] code for functions in base package

Douglas Bates bates at stat.wisc.edu
Fri May 14 01:40:12 CEST 2004


> On 13 May 2004 at 16:30, Brittany Erin Laine wrote:
> 
> > Is there any way that I can see the step by step code for functions in
> > the base package? For instance the dexp function. I am a student
> > working on writing my own function for something that is similar to
> > this dexp function and I would like to see the step by step code.
> > 
> > Brittany Laine
> > GTA WVU Statistics Department
> > 331 Hodges

As several people have pointed out the dexp function in R immediately
calls .Internal and drops down to C code.  For many of the d-p-q
functions like dexp, pexp, and qexp there are short C functions
defined in the src/nmath directory that do the calculation for a
single element of the response vector.  The C code that is called
directly by the .Internal is rather complicated but its only purpose
is to provide for the vectorization of the R function.  The real
evaluation goes on in dexp.c.  In fact, other than checking for error
conditions it amounts to a single statement

    return (give_log ?
	    (-x / scale) - log(scale) :
	    exp(-x / scale) / scale);

This is all to say that you probably don't want to go through the
step-by-step evaluation of the C code in a symbolic debugger because
most of the code that you will step through is devoted to the
vectorization.  Go directly to the corresponding C function in the
src/nmath directory.




More information about the R-help mailing list