---
layout: post
title: "Incorporating C++ code in an R package with Rcpp and devtools (CC288)"
blurb: "Will our code run any faster?"
author: "PD Schloss"
date: 2024-06-03 11:00
comments: false
youtube: ZzNwRNbD1gU
start_hash: 0ece114dfcf5263ac18446c34b0aa49a7832411b
end_hash: 23e295d7a80b6714373764565b7ac2204af49b70
---

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.

<iframe style="margin: 0 auto;display:block;" width="560" height="315" src="https://www.youtube.com/embed/{{ page.youtube }}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

## Code

You can browse the state of the repository at the

* [beginning of the episode](https://github.com/riffomonas/phylotypr/tree/{{page.start_hash}})
* [end of the episode](https://github.com/riffomonas/phylotyprr/tree/{{page.end_hash}})
