CA5 – A brief look at C++ in RStudio

CA5 Understanding the basics of C++ with R

Sometimes R code is not fast enough to process large data set and extra speed is required. Rcpp allows R programmers to seamlessly integrate C++ code into their R workflow. This post briefly discussing getting the two languages working together, write some C++ code and integrate it into R packages.

To use C++ in R packages you need to use Rcpp. To use Rcpp a compiler is required on your system or local environment. Cran have built a suite of Rtools which can be downloaded and installed to work with our environment.

RStudio can find the Rcpp files without much help from the user. Just go ahead and type require(Rcpp).

RStudio offers the option from the new file drop down to choose a c++ file with a basic function.

You can see from the image that you need to include the Rcpp library.

Rcpp has introduced types and objects that are similar to R and ensure that both work seamlessly together. C++ code can then be integrated into a package and this has been simplified by RStudio and development tools.