The goal of cpp11armadillo is to provide a novel approach to use the Armadillo C++ library by using the header-only cpp11 R package and to simplify things for the end-user.
⚠️Important⚠️: cpp11armadillo was created to ease writing functions in your own packages and does not offer on-the-fly compilation for code snippets.
The idea is to pass matrices/vectors from R to C++, write pure C++/Armadillo code for the computation, and then export the result back to R with the proper data structures.
RcppArmadillo is a popular R package used by over 1200 CRAN packages as of 2024-12-13. RcppArmadillo uses the GPL-3 license.
cpp11armadillo has different internals, even when the goal is the same, and it aims to:
The design differences result in marginally higher speed for cpp11armadillo, and the real difference for the end user is that cpp11armadillo:
This is expanded in the current preprint.
If this software is useful to you, please consider donating on Buy Me A Coffee. All donations will be used to continue improving cpp11armadillo.
Install the released version of cpp11armadillo from CRAN:
install.packages("cpp11armadillo")
Or, alternatively, install the development version of cpp11armadillo from GitHub:
::install_github("pachadotdev/cpp11armadillo") remotes
cpp11armadillo is used by the following packages:
I have provided a package template for RStudio that also works with VS Code.
The idea of this package is to be as simple as possible, with the least amount of setup to get you started.
From RStudio/VSCode, go to an empty directory of your choice and run:
::pkg_template(".", "packagename") cpp11armadillo
Then follow the instructions from the README. The template contains a simple Ordinary Least Squares (OLS) example that you can run to test the package.
The cpp11armadillotest directory contains a package that I use to test cpp11armadillo. It includes tests for OLS, eigenvalues, matrix decompositions (Cholesky and QR), the Capital Asset Pricing Model (CAPM), and data consistency between R and C++.
The vignette expands on the OLS estimator, and the hansen package expands on how to use cpp11armadillo for Econometric models.
Armadillo supports OpenBLAS, Intel MKL, and the Accelerate framework (Mac).
Install OpenBLAS on Debian-based systems with:
sudo apt-get install libopenblas-dev
Restart R and run the following command to verify:
sessionInfo()
R should display something like:
: default
Matrix products: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so; LAPACK version 3.10.0 LAPACK