Skip to content

Instantly share code, notes, and snippets.

@jakubsob
Created August 28, 2025 09:51
Show Gist options
  • Save jakubsob/95e1f98e6b01d13b55a83b6d01b01f32 to your computer and use it in GitHub Desktop.
Save jakubsob/95e1f98e6b01d13b55a83b6d01b01f32 to your computer and use it in GitHub Desktop.
Embed test snasphots in function documentation
examples <- function(name, from_dir = "tests/testthat/_snaps/ci-linux-4.4-simulated") {
dir.create(file.path("man", "figures", name), showWarnings = FALSE, recursive = TRUE)
file.copy(file.path(from_dir, name), file.path("man", "figures"), recursive = TRUE)
snaps <- list.files(file.path("man", "figures", name))
snaps |>
lapply(function(path) {
sprintf('![](%s "%s")', file.path(name, path), name)
}) |>
paste(collapse = "\n")
}
# Then in docs do:
# #' `r examples("my_function")`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment