From 0ff7bd8562a16c6dd5066294532d681b3127cba5 Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Tue, 22 Oct 2024 09:59:01 +0100 Subject: [PATCH 1/8] 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) } From 8f79d59d83bf8dbdac2bc9bf3b1d7e7c79f77256 Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Tue, 22 Oct 2024 10:04:47 +0100 Subject: [PATCH 2/8] Drop test --- tests/testthat/test-example.R | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/tests/testthat/test-example.R b/tests/testthat/test-example.R index 420f22c9..a90398bc 100644 --- a/tests/testthat/test-example.R +++ b/tests/testthat/test-example.R @@ -1,18 +1,3 @@ -test_that("can use self destructing paths", { - res <- local({ - res <- local({ - tmp <- withr::local_tempfile() - path <- suppressMessages(orderly_example("default", dest = NULL)) - list(path = path, exists_inner = file.exists(path)) - }) - res$exists_outer <- file.exists(res$path) - res - }) - expect_true(res$exists_inner) - expect_false(res$exists_outer) -}) - - test_that("can use custom path", { path <- withr::local_tempfile() res <- suppressMessages(orderly_example("default", dest = path)) From fae9722b42b990f5992a4072905edd3f0c18f7f7 Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Tue, 22 Oct 2024 15:23:43 +0100 Subject: [PATCH 3/8] Bump version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 02b6c7bc..b42ffab2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: orderly2 Title: Orderly Next Generation -Version: 1.99.47 +Version: 1.99.48 Authors@R: c(person("Rich", "FitzJohn", role = c("aut", "cre"), email = "rich.fitzjohn@gmail.com"), person("Robert", "Ashton", role = "aut"), From 0e2e1bea9faa890c0f5a0fdaf8bd7fc54c0c894a Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Tue, 22 Oct 2024 17:22:32 +0100 Subject: [PATCH 4/8] Update R/example.R MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Paul LiƩtar --- R/example.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/example.R b/R/example.R index 21b94faa..4e309fcf 100644 --- a/R/example.R +++ b/R/example.R @@ -28,7 +28,7 @@ orderly_example <- function(name, ..., dest = NULL) { } else { assert_scalar_character(dest) if (file.exists(dest)) { - cli::cli_abort("The path '{dest}' cannot exist") + cli::cli_abort("The path '{dest}' must not exist") } } orderly_init(..., root = dest) From 2a7ba43a2f5531b96ae25a8cb8a3b9398afb5c8e Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Tue, 22 Oct 2024 17:23:41 +0100 Subject: [PATCH 5/8] Redocument --- R/cleanup.R | 1 - man/orderly_cleanup.Rd | 1 - 2 files changed, 2 deletions(-) diff --git a/R/cleanup.R b/R/cleanup.R index a325a939..3732678a 100644 --- a/R/cleanup.R +++ b/R/cleanup.R @@ -42,7 +42,6 @@ ##' ##' @export ##' @examples -##' message(sprintf("Running in %s", format(environment()))) ##' # Create a simple example: ##' path <- orderly2::orderly_example("default") ##' diff --git a/man/orderly_cleanup.Rd b/man/orderly_cleanup.Rd index 32edb972..6cf66a42 100644 --- a/man/orderly_cleanup.Rd +++ b/man/orderly_cleanup.Rd @@ -60,7 +60,6 @@ files then compare that with the directory. } \examples{ -message(sprintf("Running in \%s", format(environment()))) # Create a simple example: path <- orderly2::orderly_example("default") From 084d0c2760b68d2a33ccc188655ad19edc99c8ca Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Tue, 22 Oct 2024 17:24:40 +0100 Subject: [PATCH 6/8] Use fs not unlink --- R/cleanup.R | 2 +- R/example.R | 2 +- R/orderly.R | 2 +- R/run.R | 2 +- man/orderly_cleanup.Rd | 2 +- man/orderly_example.Rd | 2 +- man/orderly_list_src.Rd | 2 +- man/orderly_run.Rd | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/R/cleanup.R b/R/cleanup.R index 3732678a..08a925cd 100644 --- a/R/cleanup.R +++ b/R/cleanup.R @@ -66,7 +66,7 @@ ##' # Do the actual deletion: ##' orderly2::orderly_cleanup("data", root = path) ##' -##' unlink(path, recursive = TRUE) +##' fs::dir_delete(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 4e309fcf..74b7c08e 100644 --- a/R/example.R +++ b/R/example.R @@ -20,7 +20,7 @@ ##' path <- orderly2::orderly_example("default") ##' orderly2::orderly_list_src(root = path) ##' -##' unlink(path, recursive = TRUE) +##' fs::dir_delete(path, recursive = TRUE) orderly_example <- function(name, ..., dest = NULL) { match_value(name, "default", call = environment()) if (is.null(dest)) { diff --git a/R/orderly.R b/R/orderly.R index a021eb42..fb4a322c 100644 --- a/R/orderly.R +++ b/R/orderly.R @@ -17,7 +17,7 @@ ##' @examples ##' path <- orderly2::orderly_example("default") ##' orderly2::orderly_list_src(root = path) -##' unlink(path, recursive = TRUE) +##' fs::dir_delete(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 b02d7dcc..28c7b4b9 100644 --- a/R/run.R +++ b/R/run.R @@ -152,7 +152,7 @@ ##' orderly2::orderly_metadata_extract(name = "data", root = path) ##' ##' # Cleanup -##' unlink(path, recursive = TRUE) +##' fs::dir_delete(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 6cf66a42..ab69bcb9 100644 --- a/man/orderly_cleanup.Rd +++ b/man/orderly_cleanup.Rd @@ -84,5 +84,5 @@ orderly2::orderly_cleanup_status("data", root = path) # Do the actual deletion: orderly2::orderly_cleanup("data", root = path) -unlink(path, recursive = TRUE) +fs::dir_delete(path, recursive = TRUE) } diff --git a/man/orderly_example.Rd b/man/orderly_example.Rd index c1d6439a..3d94aecd 100644 --- a/man/orderly_example.Rd +++ b/man/orderly_example.Rd @@ -29,5 +29,5 @@ should not form part of your workflow! path <- orderly2::orderly_example("default") orderly2::orderly_list_src(root = path) -unlink(path, recursive = TRUE) +fs::dir_delete(path, recursive = TRUE) } diff --git a/man/orderly_list_src.Rd b/man/orderly_list_src.Rd index 1cfcabb9..e62eb92c 100644 --- a/man/orderly_list_src.Rd +++ b/man/orderly_list_src.Rd @@ -26,7 +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) +fs::dir_delete(path, recursive = TRUE) } \seealso{ \link{orderly_metadata_extract} for listing packets diff --git a/man/orderly_run.Rd b/man/orderly_run.Rd index 6171a683..74511699 100644 --- a/man/orderly_run.Rd +++ b/man/orderly_run.Rd @@ -199,5 +199,5 @@ fs::dir_tree(path) orderly2::orderly_metadata_extract(name = "data", root = path) # Cleanup -unlink(path, recursive = TRUE) +fs::dir_delete(path, recursive = TRUE) } From 073eb77469625ff2faf6eef4e660521da96fbd8a Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Tue, 22 Oct 2024 17:26:20 +0100 Subject: [PATCH 7/8] Update string in test --- tests/testthat/test-example.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-example.R b/tests/testthat/test-example.R index a90398bc..71a0cf28 100644 --- a/tests/testthat/test-example.R +++ b/tests/testthat/test-example.R @@ -19,5 +19,5 @@ test_that("can set config", { test_that("error if path exists", { path <- withr::local_tempdir() expect_error(orderly_example("default", dest = path), - "The path '.+' cannot exist") + "The path '.+' must not exist") }) From e7388f381b5625ca85bda35d00417d10554d5780 Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Tue, 22 Oct 2024 17:58:43 +0100 Subject: [PATCH 8/8] Drop unwanted argument --- R/cleanup.R | 2 +- R/example.R | 2 +- R/orderly.R | 2 +- R/run.R | 2 +- man/orderly_cleanup.Rd | 2 +- man/orderly_example.Rd | 2 +- man/orderly_list_src.Rd | 2 +- man/orderly_run.Rd | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/R/cleanup.R b/R/cleanup.R index 08a925cd..00e2d36e 100644 --- a/R/cleanup.R +++ b/R/cleanup.R @@ -66,7 +66,7 @@ ##' # Do the actual deletion: ##' orderly2::orderly_cleanup("data", root = path) ##' -##' fs::dir_delete(path, recursive = TRUE) +##' fs::dir_delete(path) 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 74b7c08e..f9cd30e5 100644 --- a/R/example.R +++ b/R/example.R @@ -20,7 +20,7 @@ ##' path <- orderly2::orderly_example("default") ##' orderly2::orderly_list_src(root = path) ##' -##' fs::dir_delete(path, recursive = TRUE) +##' fs::dir_delete(path) orderly_example <- function(name, ..., dest = NULL) { match_value(name, "default", call = environment()) if (is.null(dest)) { diff --git a/R/orderly.R b/R/orderly.R index fb4a322c..4958b6c2 100644 --- a/R/orderly.R +++ b/R/orderly.R @@ -17,7 +17,7 @@ ##' @examples ##' path <- orderly2::orderly_example("default") ##' orderly2::orderly_list_src(root = path) -##' fs::dir_delete(path, recursive = TRUE) +##' fs::dir_delete(path) 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 28c7b4b9..1eebb233 100644 --- a/R/run.R +++ b/R/run.R @@ -152,7 +152,7 @@ ##' orderly2::orderly_metadata_extract(name = "data", root = path) ##' ##' # Cleanup -##' fs::dir_delete(path, recursive = TRUE) +##' fs::dir_delete(path) 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 ab69bcb9..4eb2ecaa 100644 --- a/man/orderly_cleanup.Rd +++ b/man/orderly_cleanup.Rd @@ -84,5 +84,5 @@ orderly2::orderly_cleanup_status("data", root = path) # Do the actual deletion: orderly2::orderly_cleanup("data", root = path) -fs::dir_delete(path, recursive = TRUE) +fs::dir_delete(path) } diff --git a/man/orderly_example.Rd b/man/orderly_example.Rd index 3d94aecd..6cc8b6a2 100644 --- a/man/orderly_example.Rd +++ b/man/orderly_example.Rd @@ -29,5 +29,5 @@ should not form part of your workflow! path <- orderly2::orderly_example("default") orderly2::orderly_list_src(root = path) -fs::dir_delete(path, recursive = TRUE) +fs::dir_delete(path) } diff --git a/man/orderly_list_src.Rd b/man/orderly_list_src.Rd index e62eb92c..80580773 100644 --- a/man/orderly_list_src.Rd +++ b/man/orderly_list_src.Rd @@ -26,7 +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) -fs::dir_delete(path, recursive = TRUE) +fs::dir_delete(path) } \seealso{ \link{orderly_metadata_extract} for listing packets diff --git a/man/orderly_run.Rd b/man/orderly_run.Rd index 74511699..e9b157d5 100644 --- a/man/orderly_run.Rd +++ b/man/orderly_run.Rd @@ -199,5 +199,5 @@ fs::dir_tree(path) orderly2::orderly_metadata_extract(name = "data", root = path) # Cleanup -fs::dir_delete(path, recursive = TRUE) +fs::dir_delete(path) }