main-content

## Über dieses Buch

Rcpp is the glue that binds the power and versatility of R with the speed and efficiency of C++. With Rcpp, the transfer of data between R and C++ is nearly seamless, and high-performance statistical computing is finally accessible to most R users. Rcpp should be part of every statistician's toolbox. -- Michael Braun, MIT Sloan School of Management

"Seamless R and C++ integration with Rcpp" is simply a wonderful book. For anyone who uses C/C++ and R, it is an indispensable resource. The writing is outstanding. A huge bonus is the section on applications. This section covers the matrix packages Armadillo and Eigen and the GNU Scientific Library as well as RInside which enables you to use R inside C++. These applications are what most of us need to know to really do scientific programming with R and C++. I love this book. -- Robert McCulloch, University of Chicago Booth School of Business

Rcpp is now considered an essential package for anybody doing serious computational research using R. Dirk's book is an excellent companion and takes the reader from a gentle introduction to more advanced applications via numerous examples and efficiency enhancing gems. The book is packed with all you might have ever wanted to know about Rcpp, its cousins (RcppArmadillo, RcppEigen .etc.), modules, package development and sugar. Overall, this book is a must-have on your shelf. -- Sanjog Misra, UCLA Anderson School of Management

The Rcpp package represents a major leap forward for scientific computations with R. With very few lines of C++ code, one has R's data structures readily at hand for further computations in C++. Hence, high-level numerical programming can be made in C++ almost as easily as in R, but often with a substantial speed gain. Dirk is a crucial person in these developments, and his book takes the reader from the first fragile steps on to using the full Rcpp machinery. A very recommended book! -- Søren Højsgaard, Department of Mathematical Sciences, Aalborg University, Denmark

"Seamless R and C ++ Integration with Rcpp" provides the first comprehensive introduction to Rcpp. Rcpp has become the most widely-used language extension for R, and is deployed by over one-hundred different CRAN and BioConductor packages. Rcpp permits users to pass scalars, vectors, matrices, list or entire R objects back and forth between R and C++ with ease. This brings the depth of the R analysis framework together with the power, speed, and efficiency of C++.

Dirk Eddelbuettel has been a contributor to CRAN for over a decade and maintains around twenty packages. He is the Debian/Ubuntu maintainer for R and other quantitative software, edits the CRAN Task Views for Finance and High-Performance Computing, is a co-founder of the annual R/Finance conference, and an editor of the Journal of Statistical Software. He holds a Ph.D. in Mathematical Economics from EHESS (Paris), and works in Chicago as a Senior Quantitative Analyst.

## Inhaltsverzeichnis

### Chapter 1. A Gentle Introduction to Rcpp

Abstract
This initial chapter provides a first introduction to Rcpp. It uses a somewhat slower pace and generally more gentle approach than the rest of the book in order to show key concepts which are revisited and discussed in more depth throughout the remainder. So the aim of this chapter is to cover a fairly wide range of material, but at a more introductory level for an initial overview. Two larger examples are studied in detail. We first compute the Fibonacci sequence in three different ways in two languages. Second, we simulate from a multivariate dynamic model provided by a vector autoregression.
Dirk Eddelbuettel

### Chapter 2. Tools and Setup

Abstract
Chapter 1 provided a gentle introduction to Rcpp and some of its key features. In this chapter, we look more closely at the required toolchain of compilers and related R packages needed to deploy the Rcpp package. In particular, on Windows, the Rtools collection is used and non-gcc compilers are not supported. On Unix-alike systems such as Linux and OS X, gcc/g++ is the default.
Dirk Eddelbuettel

### Chapter 3. Data Structures: Part One

Abstract
This chapter first discusses the RObject class at the heart of the Rcpp class system. While RObject is not meant to be used directly, it provides the foundation upon which many important and frequently-used classes are built. We then introduce the two core vector types NumericVector and IntegerVector. Other related vector types are briefly discussed at the end of the chapter.
Dirk Eddelbuettel

### Chapter 4. Data Structures: Part Two

Abstract
This chapter introduces several other important classes such as List, DataFrame, Function, and Environment which both correspond to key Rlanguage objects and have an underlying SEXP representation.
Dirk Eddelbuettel

### Chapter 5. Using Rcpp in Your Package

Abstract
This chapter provides an overview of how to use Rcpp when writing an R package. It shows how using the function Rcpp.package.skeleton() can create a complete and self-sufficient example of a package using Rcpp. All components of the directory tree created by Rcpp.package.skeleton() are discussed in detail. A brief case study of an existing CRAN package concludes the chapter.
Dirk Eddelbuettel

### Chapter 6. Extending Rcpp

Abstract
This chapter provides an overview of the steps programmers should follow to extend Rcpp for use with their own classes and class libraries. The packages RcppArmadillo, RcppEigen, and RcppGSLprovide working examples of how to extend Rcpp to work with, respectively, the Armadillo and Eigen C++ class libraries as well as the GNU Scientific Library.
Dirk Eddelbuettel

### Chapter 7. Modules

Abstract
This chapter discusses Rcpp modules which allow programmers to expose C++ functions and classes to R with relative ease. Rcpp modules are inspired from the Boost.Python C++ library which provides similar features for integrating Python and C++. Furthermore, Rcpp modules also offer the ability to extend C++classes exposed to Rdirectly from the Rside. This chapter discusses modules in detail and ends on an applied case study featuring the RcppCNPy package.
Dirk Eddelbuettel

### Chapter 8. Sugar

Abstract
This chapter describes Rcpp sugar which brings a higher level of abstraction to C $$++$$ code written using the Rcpp API. Rcpp sugar is based on expression templates and provides some “syntactic sugar” facilities directly in Rcpp. In this chapter, we will introduce many of the very useful Rcpp sugar features. As our focus is firmly on using Rcpp sugar, we will do so without venturing too deeply into the template meta programming approach used to implement it. Some technical details are provided at the end, and this section can be skipped by users who are interested primarily in using, rather than extending, Rcpp sugar. A brief simulation example using Rcpp sugar concludes the chapter.
Dirk Eddelbuettel

### Chapter 9. RInside

Abstract
The RInside package permits direct use of Rinside of a C++application. RInside provides an abstraction layer around the Rembedding API and makes it easier to access an Rinstance inside your application. Moreover, thanks to the classes provided by Rcpp, data interchange between Rand C++becomes very straightforward. We illustrate RInside by examining several of the many examples included with the package.
Dirk Eddelbuettel

Abstract
The RcppArmadillo package implements an easy-to-use interface to the Armadillo library. Armadillo is an excellent, modern, high-level C++library aiming to be as expressive to use as a scripting language while offering high-performance code due to modern C++design including template meta- programming.RcppArmadillo brings all these features to the Renvironment by leaning on the Rcpp interface. This chapter introduces Armadillo and provides a motivating example via a faster replacement function for fitting linear models before it discusses a detailed case study of implementing a Kalman filter in RcppArmadillo.
Dirk Eddelbuettel

### Chapter 11. RcppGSL

Abstract
The RcppGSL package provides an easy-to-use interface between data structures from the GNU Scientific Library, or GSL for short, and R by building on facilities provided in the Rcpp package. The GSL is a well-known 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. The chapter provides an introduction to the vector and matrix types in RcppGSL, illustrates their use by revisiting the linear modeling example, discusses how to deploy the RcppGSL from another package and via inline, and closes with an extended application example.
Dirk Eddelbuettel

### Chapter 12. RcppEigen

Abstract
The RcppEigen package provides an interface to the Eigen library. Eigen is a featureful C++ library which deploys modern template meta-programming techniques. It is similar to Armadillo but provides an even more granular application-programming interface (API). This chapter provides an introduction to the Rcpp Eigen package by introducing the core data structures, illustrating some of the available matrix decomposition methods and concludes with a case study of particular C++implementation (providing what is called a “factory” pattern) for different matrix decomposition approaches in order to provide a faster reimplementation of the lm method.
Dirk Eddelbuettel

### Appendix A. C++ for R Programmers

Abstract
The short appendix offers a very basic introduction to the C++language to someone already (at least somewhat) familiar with Rprogramming. Introducing all of C++in just a few pages is not really possible. Countless books have been written about the C++language since its inception in the early 1990s (and we will list a few at the end in a section on further readings).
Dirk Eddelbuettel

### Backmatter

Weitere Informationen