Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make example runner less clever #191

Merged
merged 8 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 8 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 @@ -42,6 +42,7 @@
##'
##' @export
##' @examples
##' message(sprintf("Running in %s", format(environment())))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accidental leftover?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, trying to find out what withr/devtools were thinking they had as their environment - turns out it was exactly what I expected them to have, but it just did not work

##' # Create a simple example:
##' path <- orderly2::orderly_example("default")
##'
Expand All @@ -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)
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)
##'
##' 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")
richfitz marked this conversation as resolved.
Show resolved Hide resolved
}
}
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)
##' unlink(path, recursive = TRUE)
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
##' 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,
Expand Down
13 changes: 8 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.

15 changes: 0 additions & 15 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 Down
Loading