Publications by Rcpp Gallery
RcppMLPACK2 and the MLPACK Machine Learning Library
mlpack mlpack is, to quote, a scalable machine learning library, written in C++, that aims to provide fast, extensible implementations of cutting-edge machine learning algorithms. It has been written by Ryan Curtin and others, and is described in two papers in BigLearning (2011) and JMLR (2013). mlpack uses Armadillo as the underlying linear alge...
3431 sym R (4319 sym/9 pcs) 2 img
Cleaner Generic Functions with RCPP_RETURN Macros
TL;DR C++ templates and function overloading are incompatible with R’s C API, so polymorphism must be achieved via run-time dispatch, handled explicitly by the programmer. The traditional technique for operating on SEXP objects in a generic manner entails a great deal of boilerplate code, which can be unsightly, unmaintainable, and error-p...
13107 sym R (8637 sym/79 pcs) 2 img
Passing user-supplied C++ functions with RcppXPtrUtils
Sitting on top of R’s external pointers, the RcppXPtr class provides a powerful and generic framework for Passing user-supplied C++ functions to a C++ backend. This technique is exploited in the RcppDE package, an efficient C++ based implementation of the DEoptim package that accepts optimisation objectives as both R and compiled functions (see...
2393 sym R (2302 sym/14 pcs) 2 img
Creating integer64 and nanotime vectors in C++
Motivation: More Precise Timestamps R has excellent facilities for dealing with both dates and datetime objects. For datetime objects, the POSIXt time type can be mapped to POSIXct and its representation of fractional seconds since the January 1, 1970 “epoch” as well as to the broken-out list representation in POSIXlt. Many add-on packages u...
3312 sym R (3591 sym/13 pcs) 2 img
Define a custom print method for exposed C++ classes
When writing an R package wrapping some C++ data structures, using Rcpp Modules is a convenient option. After exposing a class to R, it can be used to easily create new instances of that class. As an example, let us look at the Uniform class of the Rcpp Modules vignette: // cf Rcpp Modules vignette #include <Rcpp.h> using namespace Rcpp; clas...
1713 sym R (1771 sym/10 pcs) 2 img
Custom progress bars for RcppProgress
RcppProgress is a tool to help you monitor the execution time of your C++ code, by providing a way to interrupt the execution inside the C++ code, and also to display a progress bar indicative of the state of your computation. Additionally, it is compatible with multi-threaded code, for example using OpenMP. The initial (yet updated) article e...
5962 sym R (5177 sym/17 pcs) 2 img
Using RcppArmadillo to price European Put Options
Introduction In the quest for ever faster code, one generally begins exploring ways to integrate C++ with R using Rcpp. This post provides an example of multiple implementations of a European Put Option pricer. The implementations are done in pure R, pure Rcpp using some Rcpp sugar functions, and then in Rcpp using RcppArmadillo, which exposes th...
2812 sym R (2631 sym/16 pcs) 2 img
Introducing RcppArrayFire
Introduction The RcppArrayFire package provides an interface from R to and from the ArrayFire library, an open source library that can make use of GPUs and other hardware accelerators via CUDA or OpenCL. The official R bindings expose ArrayFire data structures as S4 objects in R, which would require a large amount of code to support all the metho...
5435 sym R (4648 sym/21 pcs) 2 img
Suppressing Call Stack Info in Rcpp-Generated Errors and Warnings
Introduction Rcpp has an elegant mechanism of exception handling whereby C++ exceptions are automatically translated to errors in R. For most projects, the Rcpp::stop wrapper (in conjunction with the BEGIN_RCPP and END_RCPP macros automatically inserted by RcppAttributes) is sufficient and easy to use, providing an Rcpp equivalent of base::stop...
2997 sym R (3541 sym/24 pcs) 2 img
Performance considerations with sparse matrices in Armadillo
Introduction Besides outstanding support for dense matrices, the Armadillo library also provides a great way to manipulate sparse matrices in C++. However, the performance characteristics of dealing with sparse matrices may be surprising if one is only familiar with dense matrices. This is a collection of observations on getting best performance ...
8481 sym R (4801 sym/36 pcs) 2 img