Blog Archives

Using RcppArmadillo to price European Put Options

February 27, 2018
By
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 the incredibly powerful linear algebra library, Armadillo. Under the Black-Scholes model...

Read more »

Custom progress bars for RcppProgress

December 27, 2017
By
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 com...

Read more »

Define a custom print method for exposed C++ classes

December 18, 2017
By
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 using namespace Rcpp; class Uniform { public: ...

Read more »

Creating integer64 and nanotime vectors in C++

November 10, 2017
By
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 use these facilities. POSIXct uses a double to provide 53 bits...

Read more »

Passing user-supplied C++ functions with RcppXPtrUtils

August 3, 2017
By
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 demo("compiled", "RcppDE") for further details). This solution has a couple of issues though: Some repetitive scaffolding...

Read more »

Cleaner Generic Functions with RCPP_RETURN Macros

July 25, 2017
By
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-prone. The...

Read more »

RcppMLPACK2 and the MLPACK Machine Learning Library

February 19, 2017
By
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 ...

Read more »

Using Rcpp with C++11, C++14 and C++17

February 18, 2017
By
Using Rcpp with C++11, C++14 and C++17

Background When we started the Rcpp Gallery in late 2012, a few of us spent the next four weeks diligently writing articles ensuring that at least one new article would be posted per day. Two early articles covered the then-budding support for C++11. ...

Read more »

Using Armadillo with SuperLU

February 17, 2017
By
Using Armadillo with SuperLU

Armadillo is very versatile C++ library for linear algebra, brough to R via the RcppArmadillo package. It has proven to be very useful and popular, and is (as of February 2017) used by well over 300 CRAN packages as indicated by the reverse depends / ...

Read more »

RcppHoney Introduction

July 25, 2016
By
RcppHoney Introduction

Rationale In C++ we often have containers that are not compatible with R or Rcpp with data already in them (std::vector, std::set, etc.). One would like to be able to operate on these containers without having to copy them into Rcpp structures like I...

Read more »

Search R-bloggers


Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)