Package: RcppGSL 0.3.13

Dirk Eddelbuettel

RcppGSL: 'Rcpp' Integration for 'GNU GSL' Vectors and Matrices

'Rcpp' integration for 'GNU GSL' vectors and matrices The 'GNU Scientific Library' (or 'GSL') is a collection of numerical routines for scientific computing. It is particularly useful for C and C++ programs as it provides a standard C interface to a wide range of mathematical routines. There are over 1000 functions in total with an extensive test suite. The 'RcppGSL' package provides an easy-to-use interface between 'GSL' data structures and R using concepts from 'Rcpp' which is itself a package that eases the interfaces between R and C++. This package also serves as a prime example of how to build a package that uses 'Rcpp' to connect to another third-party library. The 'autoconf' script, 'inline' plugin and example package can all be used as a stanza to write a similar package against another library.

Authors:Dirk Eddelbuettel and Romain Francois

RcppGSL_0.3.13.tar.gz
RcppGSL_0.3.13.tar.gz(r-4.5-noble)RcppGSL_0.3.13.tar.gz(r-4.4-noble)
RcppGSL_0.3.13.tgz(r-4.4-emscripten)RcppGSL_0.3.13.tgz(r-4.3-emscripten)
RcppGSL.pdf |RcppGSL.html
RcppGSL/json (API)
NEWS

# Install 'RcppGSL' in R:
install.packages('RcppGSL', repos = 'https://cloud.r-project.org')

Bug tracker:https://github.com/eddelbuettel/rcppgsl/issues0 issues

Uses libs:
  • gsl– GNU Scientific Library (GSL)
  • c++– GNU Standard C++ Library v3

On CRAN:

Conda-Forge:

gslcpp

7.60 score 204 packages 88 scripts 15k downloads 4 exports 1 dependencies

Last updated 2 years agofrom:90e8776a8f. Checks:2 OK. Indexed: no.

TargetResultLatest binary
Doc / VignettesOKFeb 10 2025
R-4.5-linux-x86_64OKFeb 10 2025

Exports:CFlagsfastLmfastLmPureLdFlags

Dependencies:Rcpp

RcppGSL

Rendered fromRcppGSL-intro.Rnwusingutils::Sweaveon Feb 10 2025.

Last update: 2019-10-20
Started: 2012-07-22

Citation

To cite package ‘RcppGSL’ in publications use:

Eddelbuettel D, Francois R (2023). RcppGSL: 'Rcpp' Integration for 'GNU GSL' Vectors and Matrices. R package version 0.3.13, https://CRAN.R-project.org/package=RcppGSL.

ATTENTION: This citation information has been auto-generated from the package DESCRIPTION file and may need manual editing, see ‘help("citation")’.

Corresponding BibTeX entry:

  @Manual{,
    title = {RcppGSL: 'Rcpp' Integration for 'GNU GSL' Vectors and
      Matrices},
    author = {Dirk Eddelbuettel and Romain Francois},
    year = {2023},
    note = {R package version 0.3.13},
    url = {https://CRAN.R-project.org/package=RcppGSL},
  }

Readme and manuals

RcppGSL: Rcpp Integration for GNU GSL Vectors and Matrices

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.

Examples
Faster lm() for OLS regressionlm()

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
}

Dependencies
Availabililty

On CRAN and here.

Authors

Dirk Eddelbuettel and Romain Francois

License

GPL (>= 2)

Help Manual

Help pageTopics
'Rcpp' Integration for 'GNU GSL' Vectors and MatricesRcppGSL-package RcppGSL
Bare-bones linear model fitting functionfastLm fastLm.default fastLm.formula fastLmPure
Provide RcppGSL Compiler and Linker FlagsCFlags LdFlags