- Notifications
You must be signed in to change notification settings - Fork55
RcppCore/RcppArmadillo
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
RcppArmadillo provides an interface from R to and fromArmadillo by utilising theRcppR/C++ interface library.
Armadillo is a high-quality linear algebra library for the C++ language, aiming towardsa good balance between speed and ease of use. It provides high-level syntax andfunctionality deliberately similar to Matlab (TM). Seeits website more information about Armadillo.
Glad you asked. Here is a light-weight and fast implementation of linear regression:
#include<RcppArmadillo/Lighter>// [[Rcpp::depends(RcppArmadillo)]]// [[Rcpp::export]]Rcpp::ListfastLm(const arma::mat& X,const arma::colvec& y) {int n = X.n_rows, k = X.n_cols; arma::colvec coef =arma::solve(X, y);// fit model y ~ X arma::colvec res = y - X*coef;// residualsdouble s2 =arma::dot(res, res) / (n - k);// std.errors of coefficients arma::colvec std_err =arma::sqrt(s2 *arma::diagvec(arma::pinv(arma::trans(X)*X)));returnRcpp::List::create(Rcpp::Named("coefficients") = coef,Rcpp::Named("stderr") = std_err,Rcpp::Named("df.residual") = n - k);}
You canRcpp::sourceCpp()the file above to compile the function. A version is also included in thepackageas thefastLm()function.
TheRcppArmadillo/Lighter header includesRcpp via itsRcpp/Lighter header whichprecludes some more compile-time heavy features such as 'Rcpp Modules' which we may not need. SeetheRcpp docs more details about 'Light', 'Lighter' and 'Lightest'. In the example above,the switch saves about 15% of total compilation time.
The package is mature yet under active development with releases toCRAN about once everyother month, and widely-used by other CRAN packages as can be seen from theCRAN package page. As of August 2025, there are 1266 CRAN packages using RcppArmadillo.
As of Armadillo 15.0.0, the minimum compilation standard is C++14. However, as several hundred CRANpackages still impose C++11 as their compilation standard, the RcppArmadillo package also includesthe final version allowing C++11, namely Armadillo 14.6.3, as a fallback used when C++11 compilationis detected. Conversion to and compilation under C++14 or later is encouraged. Rdefaults toC++17since version 4.3.0. SeeGitHub issue #475for more about choosing between 'legacy' Armadillo 14.6.3 or 'current' Armadillo 15.0.1 or later.
Performance is excellent, and on par or exceeding the performance of another package (or two,following a renaming) claiming otherwise. Seethis post and itsrepo for adetailed debunking of that claim.
The package contains a pdf vignette which is a pre-print of thepaper by Eddelbuettel andSanderson in CSDA (2014), as well as an introductory vignette for the sparse matrixconversions.
RcppArmadillo is aCRAN package, and lives otherwise in its own habitat onGitHub within theRcppCore GitHub organization.
Run
install.packages("RcppArmadillo")to install from your nearest CRAN mirror.
Dirk Eddelbuettel, Romain Francois, Doug Bates, Binxiang Ni, and Conrad Sanderson
GPL (>= 2)
About
Rcpp integration for the Armadillo templated linear algebra library
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.