This is a reference sheet for the readme2pkg part of the RLadies ‘Literate packaging’ March 2024 meetup which will allow for a comparative look at litr, fusen, and readme2pkg.

The packaging journey often goes something like this:

The intent of {readme2pkg} is to let you build quick packages right from a README.Rmd. The function readme2pkg::chunk_to_dir (and friends) lets you send code chunk contents to a new file in a subdirectory. This means you don’t have to manage a bunch of function files that constitute a package - at least in the early stages. Instead you can work with them in your README.Rmd.

Also, the EvaMaeRey/readme2pkg.template repo on github is a template repository meant to complement the readme2pkg workflow. Using the README.Rmd in the template, you can populate the sections with your material (introduction and functions, etc). And this README template contains a ‘living’ checklist that will help you get through the steps of creating a package, including building the file architecture, licensing, documentation, and builds. The checklist items are run through {devtools} and {usethis} packages. Code is included that lets you ‘check-off’ the items as you run the code.

The template breaks down package building into phases:

Part of the readme2pkg philosophy is that there are many reasonable pausing, stopping, and even scratch-the-project points along this progression, and the workshop will try to highlight those.

In the Denver R-Ladies meeting, I hope to get through function documentation (adding a roxygen skeleton) in Part 3 of the readme2pkg.template.

Mini workshop requirements

A. Installed Packages:

B. Template repo: EvaMaeRey/readme2pkg.template

C. Github account linked to RStudio

Option 1: {redhistogram} package

The goal of {redhistogram} is to make … easier.

Without the package, we live in the effort-ful world that follows 🏋:

library(ggplot2)

ggplot(data = cars, aes(x = dist)) + 
  geom_histogram(fill = "red")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

With the {redhistogram} package, we’ll live in a different world (🦄 🦄 🦄) where the task is a snap 🫰:

Proposed API:


library(redhistogram)
library(ggplot2)

ggplot(data = cars, aes(x = dist)) + 
  geom_histogram_red()

Part I. Work out functionality ✅

Here is a function that will do some work…

library(ggplot2)
geom_histogram_red <- function(...){
  
  geom_histogram(fill = "red", ...)
  
}

Try it out

ggplot(data = cars, aes(x = dist)) + 
  geom_histogram_red()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Option 2: {ind.recode} package (based on real-life {ind2cat}).

The goal of {ind.recode} is to make … easier.

Without the package, we live in the effort-ful world that follows 🏋:

december_grad <- c(1,1,1,0)

cat_december_grad <- ifelse(december_grad, 
                            "december grad",
                            "not december grad")

With the {ind.recode} package, we’ll live in a different world (🦄 🦄 🦄) where the task is a snap 🫰:

Proposed API:


library(ind.recode)

december_grad <- c(1,1,1,0)

cat_december_grad <- ind.recode::ind_recode(x = december_grad)

Part I. Work out functionality ✅

Here is a function that will do some work…

library(stringr)
ind_recode <- function(x){
  
  cat_true <- deparse(substitute(x)) |> 
      str_replace_all("_", " ")
  
  cat_false <- paste("not", cat_true)
  
  factor(x, labels = c(cat_false, cat_true))
  
}

Try it out

december_grad <- c(1,1,1,0)
ind_recode(december_grad)
## [1] december grad     december grad     december grad     not december grad
## Levels: not december grad december grad