Blog Archives

Getting attributes to use xts objects

January 12, 2013
By

An earlier post illustrated that R object attributes can be set at the C++ level. Naturally, we can also read them from an object. This proves particularly useful for xts objects which are, in essence, numerical matrices with added attributed that are ...

Read more »

Using Eigen for eigenvalues

January 11, 2013
By

A previous post showed how to compute eigenvalues using the Armadillo library via RcppArmadillo. Here, we do the same using Eigen and the RcppEigen package. #include <RcppEigen.h> // ] using Eigen::Map; ...

Read more »

A first lambda function with C++11 and Rcpp

January 10, 2013
By

Yesterday’s post started to explore the nice additions which the new C++11 standard is bringing to the language. One particularly interesting feature are lambda functions which resemble the anonymous functions R programmers have enjoyed all along...

Read more »

First steps in using C++11 with Rcpp

January 9, 2013
By

The recent release of the C++11 standard has brought a lot of attention to the new language features. Rcpp, as a CRAN package, follows CRAN policy in not (yet!!) supporting the standard for its purported non-portable status. Even as of the current g++ ...

Read more »

Handling Strings with Rcpp

January 8, 2013
By

This is a quick example of how you might use Rcpp to send and receive R ‘strings’ to and from R. We’ll demonstrate this with a few operations. Sort a String with R Note that we can do this in R in a fairly fast way: my_strings <-...

Read more »

Using Rcout for output synchronised with R

January 8, 2013
By

The Writing R Extensions manual, which provides the gold standard of documentation as far as extending R goes, suggests to use Rprintf and REprintf for output (from C/C++ code) as these are matched to the usual output and error streams maintained by R ...

Read more »

Using the Rcpp sugar function clamp

January 7, 2013
By

Since the 0.10.* release series, Rcpp contains a new sugar function clamp which can be used to limit vectors to both a minimum and maximim value. This recent StackOverflow question permitted clamp to shine. We retake some of the answers, including the ...

Read more »

Performance Benchmark of Running Sum Functions

January 6, 2013
By

First, let us consider a running sum function in pure R. To get started, I looked at the source code of the TTR package to see the algorithm used in runSum. The runSum function uses a Fortran routine to compute the running/rolling sum of a vector. The ...

Read more »

Using the Rcpp Timer

January 6, 2013
By

Sine the 0.10.2 release, Rcpp contains an internal class Timer which can be used for fine-grained benchmarking. Romain motivated Timer in a post to the mailing * list where Timer is used to measure the different components of the costs of random number...

Read more »

Calling R Functions from C++

January 5, 2013
By

At its very essence, Rcpp permits easy access to native R objects at the C++ level. R objects can be simple vectors, list or matrices; compound data structures created from these; objects of S3, S4 or Reference Class vintage; or language objects a...

Read more »