From aa33d54511954748eeb1e32868266e14a467f7ef Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Tue, 22 Oct 2024 09:59:01 +0100 Subject: [PATCH] Make example runner less clever --- R/cleanup.R | 13 ++++++++----- R/example.R | 16 +++++++++------- R/orderly.R | 1 + R/run.R | 3 +++ man/orderly_cleanup.Rd | 13 ++++++++----- man/orderly_example.Rd | 2 ++ man/orderly_list_src.Rd | 1 + man/orderly_run.Rd | 3 +++ 8 files changed, 35 insertions(+), 17 deletions(-) diff --git a/R/cleanup.R b/R/cleanup.R index 41026a37..a325a939 100644 --- a/R/cleanup.R +++ b/R/cleanup.R @@ -7,11 +7,11 @@ ##' directories; orderly2 has similar semantics here to git where ##' directories are never directly tracked. ##' -##' For recent `gert` (not yet on CRAN) we will ask git if files are -##' ignored; if ignored then they are good candidates for deletion! We -##' encourage you to keep a per-report `.gitignore` that lists files -##' that will copy into the source directory, and then we can use that -##' same information to clean up these files after generation. +##' For recent `gert` we will ask git if files are ignored; if ignored +##' then they are good candidates for deletion! We encourage you to +##' keep a per-report `.gitignore` that lists files that will copy +##' into the source directory, and then we can use that same +##' information to clean up these files after generation. ##' Importantly, even if a file matches an ignore rule but has been ##' committed to your repository, it will no longer match the ignore ##' rule. @@ -42,6 +42,7 @@ ##' ##' @export ##' @examples +##' message(sprintf("Running in %s", format(environment()))) ##' # Create a simple example: ##' path <- orderly2::orderly_example("default") ##' @@ -65,6 +66,8 @@ ##' ##' # Do the actual deletion: ##' orderly2::orderly_cleanup("data", root = path) +##' +##' unlink(path, recursive = TRUE) orderly_cleanup <- function(name = NULL, dry_run = FALSE, root = NULL) { status <- orderly_cleanup_status(name, root) n <- length(status$delete) diff --git a/R/example.R b/R/example.R index 34c9cbe1..21b94faa 100644 --- a/R/example.R +++ b/R/example.R @@ -19,18 +19,20 @@ ##' @examples ##' path <- orderly2::orderly_example("default") ##' orderly2::orderly_list_src(root = path) +##' +##' unlink(path, recursive = TRUE) orderly_example <- function(name, ..., dest = NULL) { match_value(name, "default", call = environment()) if (is.null(dest)) { - dest <- withr::local_tempfile(.local_envir = parent.frame()) + dest <- tempfile("orderly2_ex_") } else { - assert_scalar_character(dest, call = environment()) - } - if (file.exists(dest)) { - cli::cli_abort("The path '{dest}' cannot exist") + assert_scalar_character(dest) + if (file.exists(dest)) { + cli::cli_abort("The path '{dest}' cannot exist") + } } + orderly_init(..., root = dest) src <- orderly2_file("example") - fs::dir_copy(src, dest) - orderly2::orderly_init(..., root = dest) + fs::dir_copy(file.path(src, "src"), dest) invisible(dest) } diff --git a/R/orderly.R b/R/orderly.R index 67058364..a021eb42 100644 --- a/R/orderly.R +++ b/R/orderly.R @@ -17,6 +17,7 @@ ##' @examples ##' path <- orderly2::orderly_example("default") ##' orderly2::orderly_list_src(root = path) +##' unlink(path, recursive = TRUE) orderly_list_src <- function(root = NULL) { root_path <- orderly_src_root(root) if (!file.exists(file.path(root_path, "src"))) { diff --git a/R/run.R b/R/run.R index b7af6c81..b02d7dcc 100644 --- a/R/run.R +++ b/R/run.R @@ -150,6 +150,9 @@ ##' ##' # and we can query the metadata: ##' orderly2::orderly_metadata_extract(name = "data", root = path) +##' +##' # Cleanup +##' unlink(path, recursive = TRUE) orderly_run <- function(name, parameters = NULL, envir = NULL, echo = TRUE, location = NULL, allow_remote = NULL, pull_metadata = FALSE, search_options = NULL, diff --git a/man/orderly_cleanup.Rd b/man/orderly_cleanup.Rd index b6ebb33a..32edb972 100644 --- a/man/orderly_cleanup.Rd +++ b/man/orderly_cleanup.Rd @@ -41,11 +41,11 @@ After file deletion, we look through and remove all empty directories; orderly2 has similar semantics here to git where directories are never directly tracked. -For recent \code{gert} (not yet on CRAN) we will ask git if files are -ignored; if ignored then they are good candidates for deletion! We -encourage you to keep a per-report \code{.gitignore} that lists files -that will copy into the source directory, and then we can use that -same information to clean up these files after generation. +For recent \code{gert} we will ask git if files are ignored; if ignored +then they are good candidates for deletion! We encourage you to +keep a per-report \code{.gitignore} that lists files that will copy +into the source directory, and then we can use that same +information to clean up these files after generation. Importantly, even if a file matches an ignore rule but has been committed to your repository, it will no longer match the ignore rule. @@ -60,6 +60,7 @@ files then compare that with the directory. } \examples{ +message(sprintf("Running in \%s", format(environment()))) # Create a simple example: path <- orderly2::orderly_example("default") @@ -83,4 +84,6 @@ orderly2::orderly_cleanup_status("data", root = path) # Do the actual deletion: orderly2::orderly_cleanup("data", root = path) + +unlink(path, recursive = TRUE) } diff --git a/man/orderly_example.Rd b/man/orderly_example.Rd index b6ce6d1f..c1d6439a 100644 --- a/man/orderly_example.Rd +++ b/man/orderly_example.Rd @@ -28,4 +28,6 @@ should not form part of your workflow! \examples{ path <- orderly2::orderly_example("default") orderly2::orderly_list_src(root = path) + +unlink(path, recursive = TRUE) } diff --git a/man/orderly_list_src.Rd b/man/orderly_list_src.Rd index 214e0439..1cfcabb9 100644 --- a/man/orderly_list_src.Rd +++ b/man/orderly_list_src.Rd @@ -26,6 +26,7 @@ as the directory (e.g., \code{src/data/data.R} corresponds to \code{data}). \examples{ path <- orderly2::orderly_example("default") orderly2::orderly_list_src(root = path) +unlink(path, recursive = TRUE) } \seealso{ \link{orderly_metadata_extract} for listing packets diff --git a/man/orderly_run.Rd b/man/orderly_run.Rd index 5173ee82..6171a683 100644 --- a/man/orderly_run.Rd +++ b/man/orderly_run.Rd @@ -197,4 +197,7 @@ fs::dir_tree(path) # and we can query the metadata: orderly2::orderly_metadata_extract(name = "data", root = path) + +# Cleanup +unlink(path, recursive = TRUE) }