Keywords: R, C++, Rcpp, Package, Extension

About

Rcpp (see Eddelbuettel (2013) and Eddelbuettel et al. (2017)) has become the principal venue for extending R with compiled code. It makes it easy to extend R with C or C++ spanning the range from simple one-liners to larger routines and bindings ot entire external libraries.

Goals

Tutorial participants will line how to (easily) extend R with C++ using Rcpp.

Justification

Rcpp has become very widely used with over 1000 CRAN and BioConductor packages deploying to make R code go further and faster. While the integration is lightweight and seamless, it nevertheless brings a second programming language into the process requiring a little bit of attention for best practices. This tutorial will facilitate first steps, and provide pointers for further reference and self-study.

Description

We will motivate and introduce Rcpp as a natural extension to R providing an easy-to-use and powerful interface. Helper functions and tools including RStudio will be used to easy creation of R extensions. Several examples will introduce basic use cases including writing code with RcppArmadillo (Eddelbuettel, François, and Bates (2016), Eddelbuettel and Sanderson (2014)) which is the most widely-used package building on top of Rcpp. This provides a natual bridge to the more recent RcppMLPACK package (which combines the MLPACK machine learning library with the Armadillo linear algebra library) from which we will study one or two examples (Curtin et al. (2013), Kou and Eddelbuettel (2017), Eddelbuettel and Kou (2017)).

Outline

Starting from a brief Why? motivating the use of extensions to R, we will focus on How via a set of hands-on examples. The tutorial will go gradually from simple examples to more complicated use-cases while being hands-on and permitting participation (provided build-requirements are installed). The final examples will draw from machine learning via (Rcpp)MLPACK.

Pre-requisites

Familiarity with programming in R and basic package building is helpful but not strictly required. Likewise, some basic exposure to C and C++ is useful but not mandatory, Bringing a laptop with R, possibly RStudio, and Rcpp helps. Please ensure that Rcpp::evalCpp("2+2") (see J. J. Allaire, Eddelbuettel, and François (2015)) computes the expected answer indicating that all components are installed. See the Rcpp FAQ for installation help.

(Technical aside: The older RcppMLPACK on CRAN is self-contained with an embedded (older) copy of MLPACK and can be used as an example which will build on all platforms. Current work using the newer MLPACK 2.* which is a little more challenging on Windows and macOS due to the external MLPACK library version it relies upon.)

Potential Attendees

R users wishing to extend the scope of their analysis with compiled code, as well as those familiar with C++ aiming to combine it with R.

Instructor

Dr Dirk Eddelbuettel has been a contributor to Debian for twenty years, and to R and CRAN for fifteen years. He is the author or maintainer of over two dozen packages, including Rcpp and several packages building on top of Rcpp.

References

Allaire, J. J., Dirk Eddelbuettel, and Romain François. 2015. Rcpp Attributes. http://CRAN.R-Project.org/package=Rcpp.

Curtin, Ryan R., James R. Cline, Neil P. Slagle, William B. March, P. Ram, Nishant A. Mehta, and Alexander G. Gray. 2013. “mlpack: A Scalable C++ Machine Learning Library.” Journal of Machine Learning Research 14: 801–5.

Eddelbuettel, Dirk. 2013. Seamless R and C++ Integration with Rcpp. Use R! New York: Springer.

Eddelbuettel, Dirk, and Romain François. 2011. “Rcpp: Seamless R and C++ Integration.” Journal of Statistical Software 40 (8): 1–18. http://www.jstatsoft.org/v40/i08/.

Eddelbuettel, Dirk, and Qiang Kou. 2017. RcppMLPACK: Rcpp Interface to MLAPCK. http://github.com/rcppmlpack/rcppmlpack2.

Eddelbuettel, Dirk, and Conrad Sanderson. 2014. “RcppArmadillo: Accelerating R with High-Performance C++ Linear Algebra.” Computational Statistics and Data Analysis 71 (march): 1054–63. doi:10.1016/j.csda.2013.02.005.

Eddelbuettel, Dirk, Romain François, JJ Allaire, Kevin Ushey, Qiang Kou, Nathan Russel, John Chambers, and Douglas Bates. 2017. Rcpp: Seamless R and C++ Integration. http://CRAN.R-Project.org/package=Rcpp.

Eddelbuettel, Dirk, Romain François, and Douglas Bates. 2016. RcppArmadillo: Rcpp Integration for Armadillo Templated Linear Algebra Library. http://CRAN.R-Project.org/package=RcppArmadillo.

Kou, Qiang, and Dirk Eddelbuettel. 2017. RcppMLPACK: Rcpp Integration for Mlpack Library. http://CRAN.R-Project.org/package=RcppMLPACK.