
R Packages: vignettes + dissemination
Grayson White
Math 241
Week 12 | Spring 2026
Mon Lecture
R package documentation and metadataWed Lecture
R package testing
R package dissemination:
R Package: pdxHolesplot_holes(), a function that plots the location of the potholes along with their status.Return to our first function:
Ran so many tests!
Ran so many tests!

Standard workflow in package development:
.R script.
roxygen2)devtools::load_all()Step 3 likely involves similar informal testing as we were doing for our functions outside an R package.
Good to transition to automated testing (also called unit testing) using testthat!
testthatCreates the tests/testthat folder.
In particular, we now have a testthat.R file that will initiate all your tests every time you run devtools::check().
insert_function_name.R function in the R folder that you want tests for, create an test-insert_function_name.R for storing your tests.
test_that() tests for a particular function in your package.Expectation: Expected result of a computation
Start with expect_---()
Two main arguments:
Expectation: Expected result of a computation
Key Questions:
expect_*() functions in testthat!Error:
! 2 * 2 not equal to 4 + 1e-07.
1/1 mismatches
[1] 4 - 4 == -1e-07
Error:
! 2 * 2 not identical to 4 + 1e-07.
1/1 mismatches
[1] 4 - 4 == -1e-07
Error:
! 2 * 2 not identical to 4L.
Objects equal but not identical
Check the class of your output:
── Failure: check class ────────────────────────────────────────────────────────
plot_holes() inherits from 'ggplot2::ggplot'/'ggplot'/'ggplot2::gg'/'S7_object'/'gg' not 'data.frame'.
Error:
! Test failed
Need to put better checks in plot_holes().
There are similar functions for warnings and messages: expect_warning(), expect_message()
Option 1: Refine a specific test
Option 2: Run all tests on a function
Option 3: Run all tests on all functions
“The vignette format is perfect for showing a workflow that solves that particular problem, start to finish. Vignettes afford you different opportunities than help topics: you have much more control over the integration of code and prose and it’s a better setting for showing how multiple functions work together.” – Hadley Wickham and Jenny Bryan
To get started, run:
Which
vignettes folder.DESCRIPTION with new dependencies.pdxHoles.Rmd..gitignore.devtools::load_all() to make sure you have access to the data and functions in the package.Eventually,
Important Note:
DESCRIPTION file under either Imports or Suggests.pkgdownRun:
pkgdown.yml: The configuration file for your package..Rbuildignore.docs folder which will store all the pages for the website.To create the site, run:
DESCRIPTION file, and a vignette, then your default pkgdown site will be pretty great!To set it up so that your site can be published to a GitHub pages, run (just once):
Big Wrinkle: Can’t deploy on our private GitHub Organization.
Have to deploy through a repo tied to your individual account
Requires changing a GitHub Action setting!
Not a requirement of Project 2!
A strong tradition in the R community.
Fun way to remember and advertise a package.

A strong tradition in the R community.
Fun way to remember and advertise a package.

A strong tradition in the R community.
Fun way to remember and advertise a package.


The final week of classes… 😿
Some project work time (Monday)
Building your data science profile (Wednesday)