[R-pkgs] Rcpp 0.10.0

From: Dirk Eddelbuettel <edd_at_debian.org>
Date: Wed, 14 Nov 2012 06:46:42 -0600

A new release 0.10.0 of Rcpp is now on CRAN, bringing a number of new features to R --- please see the announcement text below.

The most direct change may be what we call 'Rcpp attributes' and which is described in a new vignette bringing the total to nine vignettes in the package.

Dirk, on behalf of Dirk, Romain, Doug, John and JJ

Version 0.10.0 of the Rcpp package is now on CRAN and its mirrors.

This new release brings a number of new features, as well as extensions to existing features, to the package. Several key aspects are highlighted below, and further details can be found in the NEWS and ChangeLog files which are included in the package.

Rcpp is an R package and associated C++ library for seamless integration between C++ and R.

It has been described in a recent paper in the Journal of Statistical Software (Vol 40, Issue 08) which is also included in the package as the "Rcpp-introduction" pdf vignette.

As of late 2012, Rcpp is used by over 80 other CRAN packages making it the most widely-used language interface for R.

Several key features of the new 0.10.0 release are described below.

Rcpp attributes are a new feature of Rcpp version 0.10.0 that provide infrastructure for seamless language bindings between R and C++. With attributes we hope to eliminate the need to write boilerplate conversion and marshaling code, make it much easier to use C++ within interactive R sessions, and reduce the learning curve associated with using C++ and R together.

Rcpp attributes derive their syntax from C++11 style attributes and are included in C++ source files using specially formatted comments. For example, the following source file includes the definition of a fibonacci function with an Rcpp::export attribute included immediately above the function definition:

#include <Rcpp.h>
using namespace Rcpp;

// [[Rcpp::export]]
int fibonacci(const int x) {

   if (x < 2)

      return x;

      return (fibonacci(x - 1)) + fibonacci(x - 2); }

The export attribute indicates that we'd like the function to be callable from R. We can now "source" this C++ file at the R prompt and then call the function as follows:

R> source("fibonacci.cpp")
R> fibonacci(20)
[1] 6765

Rcpp attributes build upon Rcpp modules (described in another vignette in the package), as well as the automatic type converters Rcpp::as<>() and Rcpp::wrap. The converters can already be used for a wide variety of standard C and C++ types, and can also be adapted to other C++ types and libraries as described in the Rcpp-extending vignette.

Rcpp attributes and their supporting functions include:

Attributes can also be used for package development via the `compileAttributes` function, which generates an Rcpp module for all exported functions within an R package.

More details are provided in the new vignette Rcpp-attributes. We also intend to provide further illustrations via our blogs following the release.

Rcpp modules provide an easy way to expose C++ functions and classes to R using a declarative syntax. We declare which functions and which classes we want to make available to R and modules takes care of automatically (via the compiler, through template deduction ...) creating the interface code between the C++ code and R.

Rcpp modules have been extended for the new release. A brief summary of new key features is:

We intend to provide example packages using these new features in the near future.

Rcpp sugar provides "syntactic sugar" familiar to R programmers at the C++ level, including a large number of vectorised functions. In this release, we added

The Rcpp::Rcout object now supports the std::flush manipulator, which calls R_FlushConsole. A new object Rcpp::Rcerr has been added with passes content for error messages to REprintf().

A side-effect of Rcpp sugar providing vectorised d/p/q/r functions for the various statistical distribution was that the scalar variants of these functions (available from Rmath.h) were masked behind a Rf_ prefix. Previously, one had to call ::Rf_pnorm5() to compute pnorm() -- but now a cleaner interface R::pnorm() is available. Unit tests were added as well.

Rcpp main page:


R-forge project page:


Dirk's blog section about Rcpp

    Rcpp: http://dirk.eddelbuettel.com/blog/code/rcpp/

Romain's blog section about Rcpp:


RStudio blog:








Questions about Rcpp should be directed to the Rcpp-devel mailing list


While we prefer the mailing list, StackOverflow has also become a frequently used resource under the [rcpp] tag:


Dirk Eddelbuettel, Romain Francois, Doug Bates, John Chambers and JJ Allaire November 2012

Dirk Eddelbuettel | edd@debian.org | http://dirk.eddelbuettel.com

R-packages mailing list
Received on Wed 14 Nov 2012 - 23:49:56 EST

This archive was generated by hypermail 2.2.0 : Wed 14 Nov 2012 - 23:50:02 EST