A little while back I had the pleasure of flying in a small Cessna with a friend and for the first time I got to see what happens in the cockpit with a real pilot. One thing I noticed was that basically you don’t lift a finger without going through some sort of check list. This starts before you even roll the airplane out of the hangar. It makes sense because flying is a pretty dangerous hobby and you want to prevent problems from occurring when you’re in the air.
That experience got me thinking about what might be the minimal check list for building an R package, a somewhat less dangerous hobby. First off, much has changed (for the better) since I started making R packages and I wanted to have some clean documentation of the process, particularly with using RStudio’s tools. So I wiped off my installations of both R and RStudio and started from scratch to see what it would take to get someone to build their first R package.
The list is basically a “pre-flight” list-–the presumption here is that you actually know the important details of building packages, but need to make sure that your environment is setup correctly so that you don’t run into errors or problems. I find this is often a problem for me when teaching students to build packages because I focus on the details of actually making the packages (i.e. DESCRIPTION files, Roxygen, etc.) and forget that way back when I actually configured my environment to do this.
Pre-flight Procedures for R Packages
- Install most recent version of R
- Install most recent version of RStudio
- Open RStudio
- Install devtools package
- Click on Project –> New Project… –> New Directory –> R package
- Enter package name
- Delete boilerplate code and “hello.R” file
- Goto “man” directory an delete “hello.Rd” file
- In File browser, click on package name to go to the top level directory
- Click “Build” tab in environment browser
- Click “Configure Build Tools…”
- Check “Generate documentation with Roxygen”
- Check “Build & Reload” when Roxygen Options window opens –> Click OK
- Click OK in Project Options window
At this point, you’re clear to build your package, which obviously involves writing R code, Roxygen documentation, writing package metadata, and building/checking your package.
If I’m missing a step or have too many steps, I’d like to hear about it. But I think this is the minimum number of steps you need to configure your environment for building R packages in RStudio.
UPDATE: I’ve made some changes to the check list and will be posting future updates/modifications to my GitHub repository.