Logistics

Last time: Version control

Why make an R Package?

“… from user to programmer to contributor, in the gradual progress that R encourages.”

~ John Chambers (Software for Data Analysis: Programming with R)

R package: Goals

What is an R Package?

library(tidyverse)
search()
##  [1] ".GlobalEnv"        "package:forcats"   "package:stringr"  
##  [4] "package:dplyr"     "package:purrr"     "package:readr"    
##  [7] "package:tidyr"     "package:tibble"    "package:ggplot2"  
## [10] "package:tidyverse" "package:stats"     "package:graphics" 
## [13] "package:grDevices" "package:utils"     "package:datasets" 
## [16] "package:methods"   "Autoloads"         "package:base"

The 5 stages of an R package

R provides tools (R CMD INSTALL, R CMD BUILD, R CMD CHECK, etc…) to move to different stages

Packages to help with developing an R package

library(devtools)
library(usethis)
# documentation
library(roxygen2) 
# tests
library(testthat)

devtools and usethis allows us to get our package up an running

“The goal of devtools is to make package development as painless as possible”

~ Hadley Wickham (R Packages)

  install.packages("devtools")
  library("devtools")

Devtools serves as a wrapper to many other useful packages

usethis focuses on automating repetitive tasks in building packages

  install.packages("usethis")
  library("usethis")

“usethis is a workflow package: it automates repetitive tasks that arise during project setup and development, both for R packages and non-package projects.”

~ usethis package description

Step 0: Setting up your github (“Github First”)

Just like in the version control we are going to us the “Github First” Approach. Here are the reminder of the steps:

In GitHub, do the following:


…then RStudio

In RStudio, do the following:

Step 1: Create the minimal source package

An R (source) package is just files in a directory, formatted in a specific way.

To create the bare bones R package, just type:

usethis::create_package("tartan") 

This should give us:

  1. Directory R/
  2. Directory man/
  3. NAMESPACE file
  4. DESCRIPTION file
  5. tartan.Rproj file (if using RStudio)

and anything else you included from intializing your git repo (.gitignore, LICENSE, etc)

The description file contains package meta-data