Skip to content

Commit

Permalink
Fix #310
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau-lilly committed Feb 15, 2021
1 parent 078e95d commit 341b6f6
Show file tree
Hide file tree
Showing 18 changed files with 214 additions and 0 deletions.
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ export(tar_destroy)
export(tar_dir)
export(tar_edit)
export(tar_envir)
export(tar_exist_meta)
export(tar_exist_objects)
export(tar_exist_process)
export(tar_exist_progress)
export(tar_exist_script)
export(tar_glimpse)
export(tar_group)
export(tar_helper)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Record info on the main process (PID, R version, `targets` version) in `_targets/meta/process` and write new functions `tar_process()` and `tar_pid()` to retrieve the data (#291, #292).
* Add a new `targets_only` argument to `tar_meta()`.
* Add new functions `tar_helper()` and `tar_helper_raw()` to write general-purpose R scripts, using tidy evaluation for as a template mechanism (#290, #291, #292, #306).
* Export functions to check the existence of various pieces of local storage: `tar_exist_meta()`, `tar_exist_objects()`, `tar_exist_progress()`, `tar_exist_progress()`, `tar_exist_script()` (#310).

## Enhancements

Expand Down
12 changes: 12 additions & 0 deletions R/tar_exist_meta.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#' @title Check if target metadata exists.
#' @export
#' @description Check if the target metadata file `_targets/meta/meta`
#' exists for the current project.
#' @details To learn more about local storage in `targets`, visit
#' <https://books.ropensci.org/targets/files.html#internal-files>.
#' @return Logical of length 1, whether the current project's metadata exists.
#' @examples
#' tar_exist_meta()
tar_exist_meta <- function() {
file.exists(path_meta())
}
16 changes: 16 additions & 0 deletions R/tar_exist_objects.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#' @title Check if local output data exists for one or more targets.
#' @export
#' @description Check if the local data files exist in
#' `_targets/objects/` for one or more targets.
#' @details To learn more about local storage in `targets`, visit
#' <https://books.ropensci.org/targets/files.html#internal-files>.
#' @return Logical of length `length(names)`, whether
#' each given target has an existing file in `_targets/objects/`
#' for the current project.
#' @param names Character vector of target names.
#' @examples
#' tar_exist_objects(c("target1", "target2"))
tar_exist_objects <- function(names) {
assert_chr(names, "names must be a character vector.")
file.exists(path_objects(names))
}
12 changes: 12 additions & 0 deletions R/tar_exist_process.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#' @title Check if process metadata exists.
#' @export
#' @description Check if the process metadata file `_targets/meta/process`
#' exists for the current project.
#' @details To learn more about local storage in `targets`, visit
#' <https://books.ropensci.org/targets/files.html#internal-files>.
#' @return Logical of length 1, whether the current project's metadata exists.
#' @examples
#' tar_exist_process()
tar_exist_process <- function() {
file.exists(path_process())
}
12 changes: 12 additions & 0 deletions R/tar_exist_progress.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#' @title Check if progress metadata exists.
#' @export
#' @description Check if the progress metadata file `_targets/meta/progress`
#' exists for the current project.
#' @details To learn more about local storage in `targets`, visit
#' <https://books.ropensci.org/targets/files.html#internal-files>.
#' @return Logical of length 1, whether the current project's metadata exists.
#' @examples
#' tar_exist_progress()
tar_exist_progress <- function() {
file.exists(path_progress())
}
10 changes: 10 additions & 0 deletions R/tar_exist_script.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#' @title Check if the target script exists.
#' @export
#' @description Check if the `_targets.R` file of the current project exists.
#' exists for the current project.
#' @return Logical of length 1, whether the current project's metadata exists.
#' @examples
#' tar_exist_script()
tar_exist_script <- function() {
file.exists(path_script())
}
7 changes: 7 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ reference:
- '`tar_progress_branches`'
- '`tar_sitrep`'
- '`tar_workspaces`'
- title: Existence
contents:
- '`tar_exist_meta`'
- '`tar_exist_objects`'
- '`tar_exist_process`'
- '`tar_exist_progress`'
- '`tar_exist_script`'
- title: Branching
contents:
- '`tar_branches`'
Expand Down
22 changes: 22 additions & 0 deletions man/tar_exist_meta.Rd

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

27 changes: 27 additions & 0 deletions man/tar_exist_objects.Rd

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

22 changes: 22 additions & 0 deletions man/tar_exist_process.Rd

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

22 changes: 22 additions & 0 deletions man/tar_exist_progress.Rd

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

18 changes: 18 additions & 0 deletions man/tar_exist_script.Rd

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

6 changes: 6 additions & 0 deletions tests/testthat/test-tar_exist_meta.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tar_test("tar_exist_meta()", {
expect_false(tar_exist_meta())
dir_create(dirname(path_meta()))
file.create(path_meta())
expect_true(tar_exist_meta())
})
5 changes: 5 additions & 0 deletions tests/testthat/test-tar_exist_objects.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
tar_test("tar_exist_objects()", {
dir_create(dirname(path_objects("x")))
file.create(path_objects("x"))
expect_equal(tar_exist_objects(c("y", "x")), c(FALSE, TRUE))
})
6 changes: 6 additions & 0 deletions tests/testthat/test-tar_exist_process.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tar_test("tar_exist_process()", {
expect_false(tar_exist_process())
dir_create(dirname(path_process()))
file.create(path_process())
expect_true(tar_exist_process())
})
6 changes: 6 additions & 0 deletions tests/testthat/test-tar_exist_progress.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tar_test("tar_exist_progress()", {
expect_false(tar_exist_progress())
dir_create(dirname(path_progress()))
file.create(path_progress())
expect_true(tar_exist_progress())
})
5 changes: 5 additions & 0 deletions tests/testthat/test-tar_exist_script.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
tar_test("tar_exist_script()", {
expect_false(tar_exist_script())
tar_script()
expect_true(tar_exist_script())
})

0 comments on commit 341b6f6

Please sign in to comment.