How to extract C code from R base and play with it?
I am trying to try C code from the R base. I may need to modify the code and compile it to understand how it works.
For example, I am trying to understand the function C_modelmatrix
.
One thing can be done: I directly modify the source code
src/library/stats/src/model.c
where it is modelmatrix()
defined. But I will need to compile the entire R source and load this newly modified R every time I change C_modelmatrix
. This process is not efficient.
Another way is to just extract the associated C code and compile it as
.so
. Then load the file .so
with the existing R. But this approach seems tricky. I have yet to figure out the exact procedure on how to do this.
Does anyone have any suggestions on what might be the best way to play with C code in an R base?
source to share
I have a source directory (from svn) at ~ / src / R-devel
~/src$ svn co https://svn.r-project.org/R/trunk R-devel
... (additional commands, e.g., R-devel/tools/rsync-recommended
I am building in ~ / bin / R-devel /
~/bin/R-devel$ CFLAGS="-g -O0" CXXFLAGS="-g -O0" ~/src/R-devel/configure
~/bin/R-devel$ make -j
I would make changes to ~ / src / R-devel / src / library / stats / src /, then in ~ / bin / R-devel / src / library / stats directory I can run
~/bin/R-devel/src/library/stats$ make
and only the statistics package will be compiled / installed.
For learning C code, I actually prefer to use gdb to navigate and interact with the code, there are a few hints available .
source to share