Skip to content

Making for loops faster with the Rcpp package

Photo of Mervyn
Hosted By
Mervyn
Making for loops faster with the Rcpp package

Details

R is an elegant language and is of growing interest to data analysts from a wide range of Academic fields. Part of its appeal is that very little code is needed to run complex tasks. But this nice use of code comes at the price of speed in many packages. This is particularly evident in for loops. If you are analysing a small dataset the difference in speed might not be noticed, because it could be micro seconds v milli seconds, i.e. both less than a second - so why would you be bothered? But on larger datasets the difference could be measured in days versus weeks. In this talk we will look at how to set up the Rcpp package and use it to rewrite some simple for loops in C++ and integrate them with R to make them faster (sometimes over 50 times!). You don't need to know C++ to get started. This talk will be of interest to those who have some practical experience of using R and would like to optimise the performance of their code , but if you are a beginner it could be interesting as we will be talking about for loops.

We will look at:

  • setting up the Rcpp package (and other recommended packages)

  • what compilers to use

  • basic expressions in C++

  • finding bottlenecks (slow points) in your R code

  • some basic comparisons of R for loops v C++ for loops

  • various ways of integrating your C++ code into R for repeated use

Photo of Cork (Ireland) R-Users Group group
Cork (Ireland) R-Users Group
See more events