[Rcpp-devel] New features in Rcpp

Kevin Ushey kevinushey at gmail.com
Wed May 7 03:07:11 CEST 2014

Hi everyone,

Two features have been committed to the master branch of Rcpp on
GitHub (https://github.com/RcppCore/Rcpp):

1. The ListOf<T> class

These function like R lists, under the assumption that each element of
that list is of type T. This should allow you to write code like:

    typedef ListOf<NumericVector> NVList;
    double add_first_three(NVList x) {
        return x[0] + x[1] + x[2];

Any Rcpp container should fit in the ListOf<T> class, and it is
possible to nest them as well (ListOf< ListOf<...> >).

2. Warnings for implicit conversions

You can now ask Rcpp to throw a warning if an implicit conversion is
done by using #define RCPP_WARN_ON_COERCE before #include <Rcpp.h>.

With this, Rcpp will now throw a warning on implicit conversions --
for example, with

    NumericVector implicit_conv(SEXP x) {
        return x;

implicit_conv(1) is okay, but implicit_conv(1L) throws a warning, stating:

    Warning message:
    In implicit_conv(1L) : coerced object from 'integer' to 'double'

This should help users of Rcpp avoid common bugs when attempting to
modify an object in place, but automatic conversion has caused them to
modify a (temporary, copied) version of that object. We are
considering making this the default behavior in the future -- any

I would greatly appreciate tests and comments, especially for the
ListOf<T> class. (See:


More information about the Rcpp-devel mailing list