Skip to content

Commit

Permalink
Make example runner less clever
Browse files Browse the repository at this point in the history
  • Loading branch information
richfitz committed Oct 22, 2024
1 parent 53cc972 commit aa33d54
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 17 deletions.
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())))
##' # 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")
}
}
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.

0 comments on commit aa33d54

Please sign in to comment.