R | Calling C++ from R
One way to significantly improve the performance of R code is to replace the most frequently used and/or time-consuming parts of the code (determined via performance profiling [1]) with equivalent C++ code, which is typically much faster.
It is very easy to use C++ code in R, which has a couple of packages to facilitate this: Rcpp [2] and cpp11 [3]. These two largely do the same job (though they can be used side-by-side). The main differences are:
Rcpp
is older and more established, and has more advanced features thancpp11
, which is more streamlinedcpp11
has support for the ALTREP framework [4], whichRcpp
does not
More information on how to use these, see [5] and [6] respectively.