Rcpp integration for GNU GSL vectors and matrices
C++ R M4 Shell
Failed to load latest commit information.
R updated / edited Jan 16, 2017
inst the RCPP_LIBS are now obsolete Jan 16, 2017
vignettes tweak to highlight boxen, rolled minor Oct 2, 2016
.gitignore accounting for vignettes/jss and rolling version Aug 30, 2015
.travis.yml switch to run.sh for Travis CI Oct 2, 2016
ChangeLog the RCPP_LIBS are now obsolete Jan 16, 2017
DESCRIPTION release 0.3.1 Oct 2, 2016
NAMESPACE release 0.2.5 Jul 7, 2015
TODO ticked off TODO items (from r1229) which were done in the 1300s Nov 28, 2010
cleanup release 0.3.0 Aug 30, 2015
configure one-char change to Makevars requested by CRAN Jan 7, 2015
rcppgsl.Rproj add RStudion project file, and remove pdf vignettes in cleanup Jul 6, 2015


RcppGSL Build Status License CRAN Downloads

This package uses Rcpp to connect the R system to the GNU GSL, a collection of numerical routines for scientific computing, particularly its vector and matrix classes.


Faster lm() for OLS regression

The fastLm() function included as file src/fastLm.cpp in the package:

#include <RcppGSL.h>

#include <gsl/gsl_multifit.h>
#include <cmath>

// [[Rcpp::export]]
Rcpp::List fastLm(const RcppGSL::Matrix &X, const RcppGSL::Vector &y) {

    int n = X.nrow(), k = X.ncol();
    double chisq;

    RcppGSL::Vector coef(k);                // to hold the coefficient vector 
    RcppGSL::Matrix cov(k,k);               // and the covariance matrix

    // the actual fit requires working memory we allocate and free
    gsl_multifit_linear_workspace *work = gsl_multifit_linear_alloc (n, k);
    gsl_multifit_linear (X, y, coef, cov, &chisq, work);
    gsl_multifit_linear_free (work);

    // assign diagonal to a vector, then take square roots to get std.error
    Rcpp::NumericVector std_err;
    std_err = gsl_matrix_diagonal(cov);     // need two step decl. and assignment
    std_err = Rcpp::sqrt(std_err);          // sqrt() is an Rcpp sugar function

    return Rcpp::List::create(Rcpp::Named("coefficients") = coef, 
                              Rcpp::Named("stderr")       = std_err,
                              Rcpp::Named("df.residual")  = n - k);


A simple column norm

This example comes from the complete example package included in RcppGSL and is from the file inst/examples/RcppGSLExample/src/colNorm.cpp

#include <RcppGSL.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_blas.h>

// [[Rcpp::export]]
Rcpp::NumericVector colNorm(const RcppGSL::Matrix & G) {
    int k = G.ncol();
    Rcpp::NumericVector n(k);           // to store results
    for (int j = 0; j < k; j++) {
        RcppGSL::VectorView colview = gsl_matrix_const_column (G, j);
        n[j] = gsl_blas_dnrm2(colview);
    return n;                           // return vector



On CRAN, here and on its package page.


Dirk Eddelbuettel and Romain Francois


GPL (>= 2)