Skip to content

Commit

Permalink
Merge pull request #191 from mrc-ide/mrc-5791
Browse files Browse the repository at this point in the history
Make example runner less clever
  • Loading branch information
richfitz authored Oct 22, 2024
2 parents 37bdb29 + e7388f3 commit c499952
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 34 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]"),
person("Robert", "Ashton", role = "aut"),
Expand Down
12 changes: 7 additions & 5 deletions R/cleanup.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -65,6 +65,8 @@
##'
##' # Do the actual deletion:
##' orderly2::orderly_cleanup("data", root = path)
##'
##' fs::dir_delete(path)
orderly_cleanup <- function(name = NULL, dry_run = FALSE, root = NULL) {
status <- orderly_cleanup_status(name, root)
n <- length(status$delete)
Expand Down
16 changes: 9 additions & 7 deletions R/example.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@
##' @examples
##' path <- orderly2::orderly_example("default")
##' orderly2::orderly_list_src(root = path)
##'
##' fs::dir_delete(path)
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}' must not 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)
}
1 change: 1 addition & 0 deletions R/orderly.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
##' @examples
##' path <- orderly2::orderly_example("default")
##' orderly2::orderly_list_src(root = path)
##' fs::dir_delete(path)
orderly_list_src <- function(root = NULL) {
root_path <- orderly_src_root(root)
if (!file.exists(file.path(root_path, "src"))) {
Expand Down
3 changes: 3 additions & 0 deletions R/run.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@
##'
##' # and we can query the metadata:
##' orderly2::orderly_metadata_extract(name = "data", root = path)
##'
##' # Cleanup
##' 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,
Expand Down
12 changes: 7 additions & 5 deletions man/orderly_cleanup.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/orderly_example.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/orderly_list_src.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions man/orderly_run.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 1 addition & 16 deletions tests/testthat/test-example.R
Original file line number Diff line number Diff line change
@@ -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))
Expand All @@ -34,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")
})

0 comments on commit c499952

Please sign in to comment.