How to Make an R Package

I recently created my first R package, {ib}, currently containing my custom ggplot2 theme and other functions for ggplot2 for my personal use. Since it was my first time making a package, there was a bit of a learning curve and I wanted to compile all of the resources I used to create it so that I can reference them the next time I make a package.

Jumping off point: Stat 431’s Lab 4: Create a Package to get started quickly. It covers creating the package, version control, setting up preliminaries, pushing to GitHub. What I did that’s not in the tutorial: make an RStudio project for the package, which created my git repository in the same step. I also didn’t do the “Branch and Pull Request” workflow since I’m the only one working on this.

Everything else: I referenced Hadley Wickham and Jenny Bryan‘s R Packages and looked at the code of existing packages. Since the current functions are themes functions for ggplot2, the package whose source code I looked at most was hrbrthemes. Looking at an example was really helpful, especially when making the DESCRIPTION and adding roxygen comments.

Below are the links to the chapters I used most.

This package has been very simple, so that’s basically all that I’ve used from the book so far, but I’m sure I’ll be using the other sections in the future. It’s a great resource and I love how thorough it is.

comments powered by Disqus