Articles by Rcpp Gallery

Using iconv via the R exported header

March 5, 2021 | Rcpp Gallery

Introduction Character encodings can be tricky and frustrating to deal with. Several newer languages such as Go or Julia default to native UTF-8 on all platforms, greatly facilitating and easing use of characters with languages other than English on ... [Read more...]

Using Scheme from R via Guile and Rcpp

December 16, 2020 | Rcpp Gallery

Introduction GNU Guile is a programming language “designed to help programmers create flexible applications that can be extended by users or other programmers with plug-ins, modules, or scripts”. It is an extension language platform, and contains an e... [Read more...]

Handling R6 objects in C++

July 30, 2020 | Rcpp Gallery

Introduction When we are using R6 objects and want to introduce some C++ code in our project, we may also want to interact with these objects using Rcpp. With this objective in mind, the key to interacting with R6 objects is that they are essentially... [Read more...]

Mixing Rcpp modules and Rcpp attributes

June 7, 2020 | Rcpp Gallery

Introduction With Rcpp attributes Rcpp modules (described in the Rcpp vignettes) it is easy to expose C++ classes and functions to R. This note describes how to use classes exported by modules in conjunction with functions exported using Rcpp attributes through the use of RCPP_EXPOSED* macros. In the following ... [Read more...]

Recreating rmultinom and rpois with Rcpp

June 5, 2020 | Rcpp Gallery

Sometimes one needs to mimic the exact behavior of R’s Distributions within C++ code. The incredible Rcpp team has provided access to these distributions through Rmath.h (in the R:: namespace), as well as through the Rcpp:: namespace where there can ... [Read more...]

Creating a data.table from C++

May 4, 2020 | Rcpp Gallery

Introduction Rcpp provides the DataFrame class which enables us to pass data.frame object between C++ and R. DataFrame objects are key to R and used very widely. They also provide the basis from which two key packages extend them. One of these, the tibble package, operates in a similar ... [Read more...]

Using RcppParallel to aggregate to a vector

November 4, 2019 | Rcpp Gallery

This article demonstrates using the RcppParallel package to aggregate to an output vector. It extends directly from previous demonstrations of single-valued aggregation, through providing necessary details to enable aggregation to a vector, or by exten... [Read more...]

Performance considerations with sparse matrices in Armadillo

April 17, 2018 | Rcpp Gallery

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 ... [Read more...]

Introducing RcppArrayFire

March 6, 2018 | Rcpp Gallery

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 ... [Read more...]

Using RcppArmadillo to price European Put Options

February 27, 2018 | Rcpp Gallery

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 ... [Read more...]

Custom progress bars for RcppProgress

December 27, 2017 | Rcpp Gallery

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...]

Creating integer64 and nanotime vectors in C++

November 10, 2017 | Rcpp Gallery

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 ... [Read more...]

Passing user-supplied C++ functions with RcppXPtrUtils

August 3, 2017 | Rcpp Gallery

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 ... [Read more...]

Cleaner Generic Functions with RCPP_RETURN Macros

July 25, 2017 | Rcpp Gallery

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, ... [Read more...]

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

February 18, 2017 | Rcpp Gallery

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...]
1 2 3 6

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)