Romain Francois — written Dec 19, 2012 — source
This example will take a C++ function written using the standard Rcpp API and transform it to something looking much more like it’s R equivilant using Rcpp sugar.
The following function foo
transforms two numeric vectors into a
third one:
While this code is performant, the equivilant R code would be much shorter:
Rcpp sugar enables us to write C++ code that operates on entire vectors
much like we do in R. Re-writing using the sugar ifelse
function and
numeric and comparison operators yields the identical one-line
implementation:
tags: sugar
Tweet