Skip to content
R bindings for xtensor
Branch: master
Clone or download
Latest commit c9ab0fe Apr 18, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
cmake Add basic appveyor testing Jul 5, 2017
readthedocs.yml Add readthedocs yml configuration Jul 27, 2017 iterate on xtensor-r Jun 13, 2017


Travis Appveyor Documentation Join the Gitter Chat

R bindings for the xtensor C++ multi-dimensional array library.

  • xtensor is a C++ library for multi-dimensional arrays enabling numpy-style broadcasting and lazy computing.

  • xtensor-r enables inplace use of R arrays in C++ with all the benefits from xtensor

xtensor-r can be used either to author C++ extensions for R with Rcpp, or applications that embed the R interpreter with RInside.


#include <numeric>                    // Standard library import for std::accumulate
#define STRICT_R_HEADERS              // Otherwise a PI macro is defined in R
#include "xtensor/xmath.hpp"          // xtensor import for the C++ universal functions
#include "xtensor-r/rarray.hpp"       // R bindings

#include <Rcpp.h>

using namespace Rcpp;

// [[Rcpp::plugins(cpp14)]]

// [[Rcpp::export]]
double sum_of_sines(xt::rarray<double>& m)
    auto sines = xt::sin(m);  // sines does not actually hold values.
    return std::accumulate(sines.cbegin(), sines.cend(), 0.0);
v <- matrix(0:14, nrow=3, ncol=5)
s <- sum_of_sines(v)

# prints 1.2853996391883833


Installation of the standalone C++ library

xtensor-r a header-only C++ library. It has been packaged for the conda package manager.

conda install xtensor-r -c conda-forge

xtensor-r can be installed from source with cmake in any installation prefix. For example, on unix systems

cmake -D CMAKE_INSTALL_PREFIX=/prefix/path/ .
make install

Installation of the R package

We provide a R package for Xtensor on both conda and CRAN (Comprehensive R Archive Network). The packaging boilerplate for the R package is available at

To install the R package with conda:

conda install r-xtensor -c conda-forge

To install the R package from CRAN:


or from the GitHub repository using devtools


The CRAN package vendors the headers for xtensor-r, xtensor, xtlandxsimd`.


To get started with using xtensor-r, check out the full documentation

Dependencies on xtensor and Rcpp

xtensor-r depends on the xtensor and Rcpp libraries

xtensor-r xtensor Rcpp
master ^0.20.4 ^1.0
0.11.0 ^0.20.4 ^1.0
0.10.0 ^0.19.4 ^1.0
0.9.0 ^0.19.0 ^1.0
0.8.2 ^0.18.2 ^0.12.11
0.8.1 ^0.18.1 ^0.12.11
0.8.0 ^0.18.0 ^0.12.11
0.7.0 ^0.17.1 ^0.12.11
0.6.1 ^0.16.2 ^0.12.11
0.6.0 ^0.16.1 ^0.12.11
0.5.0 ^0.15.4 ^0.12.11
0.4.0 ^0.14.1 ^0.12.11
0.3.0 ^0.13.1 ^0.12.11
0.2.0 ^0.12.0 ^0.12.11
0.1.1 ^0.11.2 ^0.12.11
  • Core xtensor headers are vendored in the CRAN package.
  • When using the conda, or debian package managers, xtensor-r has a dependency on xtensor.


We use a shared copyright model that enables all contributors to maintain the copyright on their contributions.

This software is licensed under the BSD-3-Clause license. See the LICENSE file for details.

You can’t perform that action at this time.