Incorporating C++ code in an R package with Rcpp and devtools (CC288)

June 3, 2024 • PD Schloss • 1 min read

Sometimes R code just isn’t fast enough. When you’ve tried all of the other options, rewriting the R code in C++ can be a great option. In this Code Club, Pat uses the Rcpp package to add C++ code to his phylotypr package. Using the devtools use_rcpp function he shows how to create the framework for incorporating C++ code. Then he uses the microbenchmark package to optimize his Rcpp code to see if he can make it faster than his base R code. Can he do it? This episode is part of an ongoing effort to develop an R package that implements the naive Bayesian classifier.

Code

You can browse the state of the repository at the