Last week we released the first official version of
cinterpolate to available on CRAN. This package provides a minimal set of interpolation methods (piecewise constant, linear and spline) designed to be compatible with R’s builtin
spline functions, but but callable from C. It will primarily be of interest to people writing R packages that include C or C++.
When writing an R package with C or C++ extensions, you have to forgo many of the the functions that make operating in a high-level easy. R’s C API (and Rcpp, which reflects it) includes lots of helper functions for common tasks but this is a small list compared to what you might want to do from R.
odin we need to be able to interpolate functions of time (e.g., a trace of temperature against time, or a square wave representing pulses of interventions) from C code. For piecewise constant and linear functions this is straightforward, but for splines it is a little more involved. In all cases, we want look-up of the interpolated functions to be fast - using bisection searches and starting searches near the last point that was used.
The original version of the code that became
cinterpolate of this was bundled into odin but this quickly became a pain to test so it was broken out into its own package.
To get started with
cinterpolate, see the the vignette, which explains how to configure your
DESCRIPTION and how to use the functions. The C API includes only 3 functions (allocation, evaluation and cleanup).