Created
August 28, 2025 09:51
-
-
Save jakubsob/95e1f98e6b01d13b55a83b6d01b01f32 to your computer and use it in GitHub Desktop.
Embed test snasphots in function documentation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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('', 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