README.md

Debugging an R package with Compiled Code

Author :

License: MIT

Purpose:

This package is my attempt to understand debugging compiled code. I'm having difficulty debugging segmentation faults in R-TDA. Some outstanding questions : 1. How is the compiled code in R-TDA actually compiled. There isn't a Makefile or configure file? 2. Why can't I get useful debugging information in _TDA_Kde()? 3. How does R mangle (see Rcppexports.cpp) the functions in the src code? 4. How does ~/.R/Makevars control compilation flags.

Installation :

Steps : 1. install.packages("devtools") 2. devtools::install_github("klutometis/roxygen")

Running :

Notes :

If you've cloned this repo: 1. library(devtools); library(roxygen2) 2. document()

To create a raw package (NOT what you'll do if you've cloned this repo): 1. load devtools and roxygen2 2. create("debug.Compiled.R.Packages") # Create director 3. document() # Generates man and NAMESPACE 4. setwd(".."); install("debug.Compiled.R.Packages") a) Evidently, MUST have all code wrapped within functions. The files get sourced. 5. usethis::use_rcpp() a) Creates src b) Adds Rcpp to LinkingTo and Imports in DESCRIPTION c) Creates src/.gitignore so that compiled code doesn't accidently get committed to git repo 6. devtools::load_all() per ref 4 this is dangerous

On Compiling : 1. Note that package/src/Makevars takes precedence over ~/.R/Makevars. This is largely why I'm having difficulty debugging R-TDA 2. R magically compiles code into shared library

On Namespace : 1. Can selectively export functions to users, hold back other functions for internal use. 2. search() provides a list of search paths. 3. library() loads the package into memory and then adds it to search path. a) Never use in a package, only in external scripts calling the package

References :

  1. Not So Standard Deviations by Hillary Parker
  2. Fong Chun Chan's Blog
  3. Compiled Code - R-pkgs.org
  4. Understanding Makevars - Stackoverflow
  5. Rcpp Vignettes
  6. Writing R Extensions


astrophys/Debug_R_Segfault documentation built on Dec. 19, 2021, 5:40 a.m.