Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Rcpp integration for the Armadillo templated linear algebra library

NotificationsYou must be signed in to change notification settings

RcppCore/RcppArmadillo

Repository files navigation

CILicenseCRANDebian packager-universeDependenciesCoverage StatusLast CommitDownloads (monthly)Downloads (total)CRAN useCRAN indirectBioConductor useCSDA

Synopsis

RcppArmadillo provides an interface from R to and fromArmadillo by utilising theRcppR/C++ interface library.

What is Armadillo?

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.

So give me an example!

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.

Status

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.

Documentation

The package contains a pdf vignette which is a pre-print of thepaper by Eddelbuettel and Sandersonin CSDA (2014), as well as an introductory vignette for the sparsematrix conversions.

Installation

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.

Authors

Dirk Eddelbuettel, Romain Francois, Doug Bates, Binxiang Ni, and Conrad Sanderson

License

GPL (>= 2)

About

Rcpp integration for the Armadillo templated linear algebra library

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp