simplec, simplecall, simplercpp - demo packages incorporating C code

3 demo packages

In the process of working out how to best call C code in an R package, I created 3 small demonstration packages showing how C code can be included and called within a package.

  • simplec A package using .C() to interface with C code
  • simplecall A package using .Call() to interface with C code
  • simplercpp A package using {Rcpp} to interface with C code

Rough comparison of .C(), .Call() and {Rcpp}

.C() .Call() Rcpp
Overview No real understanding of R objects Need to understand SEXP macros & internals C++ classes hide the complexity of the SEXP internals
What code? Basic C code. Numeric calcs. Complex C code. Can manipulate R objects from C Complex C and C++ code involving numerics and R objects
Pros Simple to understand and use Simple. No unnecessary copying. Great documentation. Wrapping of R objects very intuitive.
Cons Too simple for most interesting things Need to understand SEXP & R internals
Cons Performs copying of data to call functions
Demo R package {simplec} {simplecall} {simplercpp}