Skip to content

Commit

Permalink
Fix #1153
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau-lilly committed Sep 22, 2023
1 parent 4cbd64b commit 2606154
Show file tree
Hide file tree
Showing 18 changed files with 288 additions and 7 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Description: Pipeline tools coordinate the pieces of computationally
The methodology in this package
borrows from GNU 'Make' (2015, ISBN:978-9881443519)
and 'drake' (2018, <doi:10.21105/joss.00550>).
Version: 1.3.0.9000
Version: 1.3.0.9001
License: MIT + file LICENSE
URL: https://docs.ropensci.org/targets/, https://github.com/ropensci/targets
BugReports: https://github.com/ropensci/targets/issues
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,10 @@ export(tar_callr_inner_try)
export(tar_cancel)
export(tar_canceled)
export(tar_config_get)
export(tar_config_projects)
export(tar_config_set)
export(tar_config_unset)
export(tar_config_yaml)
export(tar_counter)
export(tar_crew)
export(tar_cue)
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# targets 1.3.0.9000 (development)
# targets 1.3.0.9001 (development)

* Add `tar_config_projects()` and `tar_config_yaml()` (#1153, @psychelzh).

# targets 1.3.0

Expand Down
2 changes: 1 addition & 1 deletion R/tar_config_get.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ tar_config_get <- function(
tar_assert_scalar(project)
choices <- setdiff(names(formals(tar_config_set)), c("config", "project"))
tar_assert_flag(name, choices = choices)
yaml <- tar_config_read_yaml(config)
yaml <- tar_config_yaml(config)
value <- if_any(
tar_config_is_multi_project(yaml, config),
tar_config_get_multi_project(name, yaml, project, memory_init()),
Expand Down
18 changes: 18 additions & 0 deletions R/tar_config_list.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#' @title List projects.
#' @export
#' @family configuration
#' @description List the names of projects defined in `_targets.yaml`.
#' @return Character vector of names of projects defined in `_targets.yaml`.
#' @inheritSection tar_meta Storage access
#' @inheritSection tar_config_set Configuration
#' @inheritParams tar_config_set
#' @examples
#' yaml <- tempfile()
#' tar_config_set(store = "my_store_a", config = yaml, project = "project_a")
#' tar_config_set(store = "my_store_b", config = yaml, project = "project_b")
#' tar_config_projects(config = yaml)
tar_config_projects <- function(
config = Sys.getenv("TAR_CONFIG", "_targets.yaml")
) {
names(tar_config_yaml(config = config))
}
5 changes: 1 addition & 4 deletions R/tar_config_set.R
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,7 @@ tar_config_set <- function(
tar_config_assert_store(store)
tar_config_assert_use_crew(use_crew)
tar_config_assert_workers(workers)
yaml <- tar_config_read_yaml(config)
if (!tar_config_is_multi_project(yaml, config)) {
yaml <- tar_config_convert_multi_project(yaml, config)
}
yaml <- tar_config_yaml(config = config)
yaml[[project]]$inherits <- inherits %|||% yaml[[project]]$inherits
yaml[[project]]$garbage_collection <- garbage_collection %|||%
yaml[[project]]$garbage_collection
Expand Down
25 changes: 25 additions & 0 deletions R/tar_config_yaml.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#' @title Read `_targets.yaml`.
#' @export
#' @family configuration
#' @description Read the YAML content of `_targets.yaml`.
#' @return Nested list of fields defined in `_targets.yaml`.
#' @inheritSection tar_meta Storage access
#' @inheritSection tar_config_set Configuration
#' @inheritParams tar_config_set
#' @examples
#' yaml <- tempfile()
#' tar_config_set(store = "my_store_a", config = yaml, project = "project_a")
#' tar_config_set(store = "my_store_b", config = yaml, project = "project_b")
#' str(tar_config_yaml(config = yaml))
tar_config_yaml <- function(
config = Sys.getenv("TAR_CONFIG", "_targets.yaml")
) {
tar_assert_chr(config)
tar_assert_scalar(config)
yaml <- tar_config_read_yaml(config)
if_any(
tar_config_is_multi_project(yaml, config),
yaml,
tar_config_convert_multi_project(yaml, config)
)
}
2 changes: 2 additions & 0 deletions man/tar_config_get.Rd

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

103 changes: 103 additions & 0 deletions man/tar_config_projects.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/tar_config_set.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/tar_config_unset.Rd

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

103 changes: 103 additions & 0 deletions man/tar_config_yaml.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/tar_envvars.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/tar_option_get.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/tar_option_reset.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/tar_option_set.Rd

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

7 changes: 7 additions & 0 deletions tests/testthat/test-tar_config_projects.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test_that("tar_config_projects()", {
yaml <- tempfile()
tar_config_set(store = "my_store_a", config = yaml, project = "project_a")
tar_config_set(store = "my_store_b", config = yaml, project = "project_b")
out <- tar_config_projects(config = yaml)
expect_equal(sort(out), sort(c("project_a", "project_b")))
})
11 changes: 11 additions & 0 deletions tests/testthat/test-tar_config_yaml.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
test_that("tar_config_projects()", {
yaml <- tempfile()
tar_config_set(store = "my_store_a", config = yaml, project = "project_a")
tar_config_set(store = "my_store_b", config = yaml, project = "project_b")
out <- tar_config_yaml(config = yaml)
exp <- list(
project_a = list(store = "my_store_a"),
project_b = list(store = "my_store_b")
)
expect_equal(out, exp)
})

0 comments on commit 2606154

Please sign in to comment.