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:
Step 000. Do a thing happily with some existing tools 1-20x
Step 00. Do a thing again 21-1000+x with some existing tools
Step 0. Decide you’ve had enough/flash of ‘what-if there’s another way’ insight
Step 1. Write functionality
Step 2. Prepare a package to deliver functionality
Step 3. Maintain package
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 1. Goals definition; what package functionality should deliver
Part 2. Construct functions and a minimal viable package
Part 3. Listen and iterate; (soliciting feedback)
Part 4. Refine and make robust
Part 5. Spread the good news; seek a wider audience
Part 6. Commit. Share on CRAN or RUniverse
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.
A. Installed Packages:
usethis
; devtools
; ggplot2
or stringr
(depending on worked example below)remotes::install_github("EvaMaeRey/readme2pkg")
B. Template repo: EvaMaeRey/readme2pkg.template
C. Github account linked to RStudio
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()
Here is a function that will do some work…
library(ggplot2)
geom_histogram_red <- function(...){
geom_histogram(fill = "red", ...)
}
ggplot(data = cars, aes(x = dist)) +
geom_histogram_red()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
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)
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))
}
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