- Welcome to the ggtedious workshop!
- Part 1. Work on functionality
- Step 0. Do it with base ggplot2 can become problem statement later
- Step 0.b Write like-to-have code code chunk option eval = F
- Step 1. Write compute group function and test
- Step 2. Pass to ggproto object
- Step 3. Write geom_post() functions
- Step 3.1 Bonus, write geom_lollipop with list mechanism
- Step 4. Test it out enjoy! (possibly basis of examples and tests)
- Step 5. Write messages/warnings etc in the function
- Part II. Packaging and documentation 🚧
✅
- Phase 1. Minimal working
package
- Bit A. Created package archetecture, running
devtools::create(".")
in interactive session. 🚧 ✅ - Bit B. Added roxygen skeleton? 🚧 ✅
- Bit C. Managed dependencies ? 🚧 ✅
- Bit D. Moved functions R folder? 🚧 ✅
- Bit E. Run
devtools::check()
and addressed errors. 🚧 ✅ - Bit F. Build package 🚧 ✅
- Bit G. Write traditional README that uses built package (also serves as a test of build. 🚧 ✅
- Bit H. Chosen a license? 🚧 ✅
- Bit I. Add lifecycle badge (experimental) 🚧 ✅
- Bit A. Created package archetecture, running
- Phase 2: Listen & iterate 🚧 ✅
- Phase 3: Let things settle
- Phase 4. Promote to wider audience…
- Phase 5: Harden/commit
- Phase 1. Minimal working
package
- Appendix: Reports, Environment
Let’s build a cool ggplot2 extension function. And then let’s put it in a package. And test! Maybe it will be tedious, but more fun in good company?
‘Testing your code can be painful and tedious, but it greatly increases the quality of your code.’ - testthat introduction (probably Hadley Wickham)
In this workshop, we’ll build and strengthen package building and test writing muscles.
https://angeladuckworth.com/grit-scale/
Meeting objectives:
- Practice a
compute_group
easy geom extension by creating geom_post(). - Put them in a package using best practices.
- Meet like-minded stats educators, ggplot2 extenders, and package developers.
Prerequisite:
Having written a ‘compute group’ geom extension. See: https://evamaerey.github.io/mytidytuesday/2022-01-03-easy-geom-recipes/easy_geom_recipes.html Seasoned R/ggplot2 users mostly spent ~ 15 minutes on each recipe.
prize_wheel <- data.frame(probs = c(.7, .2, .1), payout = c(0, 1, 5))
library(ggplot2)
ggplot(prize_wheel) +
aes(x = payout, y = probs) +
geom_point() +
aes(xend = payout, yend = 0) +
geom_segment()
# would show just line
ggplot(prize_wheel) +
aes(x = payout, y = probs) +
geom_post()
# line and dot
ggplot(prize_wheel) +
aes(x = payout, y = probs) +
geom_point() +
geom_lollipop()
reference: https://evamaerey.github.io/mytidytuesday/2022-01-03-easy-geom-recipes/easy_geom_recipes.html
geom_lollipop <- function(...){
list(
geom_post(...),
geom_point(...)
)
}
devtools::create(".")
Use a roxygen skeleton for auto documentation and making sure proposed functions are exported. Generally, early on, I don’t do much (anything) in terms of filling in the skeleton for documentation, because things may change.
Package dependencies managed, i.e. depend::function()
in proposed
functions and declared in the DESCRIPTION
usethis::use_package("ggplot2")
Use new {readme2pkg} function to do this from readme…
library(tidyverse)
readme2pkg::chunk_to_r("geom_post")
devtools::check(pkg = ".")
devtools::build()
The goal of the {ggtedious} package is to make it easy to draw posts (and to learn about package building and testing)
Install package with:
remotes::install_github("EvaMaeRey/ggtedious")
Once functions are exported you can remove go to two colons, and when things are are really finalized, then go without colons (and rearrange your readme…)
library(ggtedious)
usethis::use_mit_license()
usethis::use_lifecycle_badge("experimental")
Try to get feedback from experts on API, implementation, default decisions. Is there already work that solves this problem?
That would look like this…
library(testthat)
test_that("calc times 2 works", {
expect_equal(times_two(4), 8)
expect_equal(times_two(5), 10)
})
readme2pkg::chunk_to_tests_testthat("test_calc_times_two_works")
usethis::use_pkgdown()
pkgdown::build_site()
readLines("DESCRIPTION")