Skip to content

Commit

Permalink
Set level_separation with tar_config_set() (#1085)
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau-lilly committed Jun 22, 2023
1 parent 5da85f6 commit dcbccfa
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 2 deletions.
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# targets 1.1.3.9000 (development)

## `crew` integration

* Do not assume S3 classes when validating `crew` controllers.
* Suggest a crew controller in the `_targets.R` file from `use_targets()`.
* Make `tar_crew()` compatible with `crew` >= 0.2.1.9011.

## Other improvements

* Set default `level_separation` arguments with `tar_config_set()` (#1085, @Moohan).

# targets 1.1.3

* Decide on `nanonext` usage in `time_seconds_local()` at runtime and not installation time. That way, if `nanonext` is removed after `targets` is installed, functions in `targets` still work. Fixes the CRAN issues seen in `tarchetypes`, `jagstargets`, and `gittargets`.
Expand Down
2 changes: 2 additions & 0 deletions R/tar_config_get.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ tar_config_get_project <- function(name, yaml) {
name,
inherits = yaml$inherits,
garbage_collection = yaml$garbage_collection %|||% FALSE,
level_separation = yaml$level_separation,
reporter_make = yaml$reporter_make %|||% "verbose",
reporter_outdated = yaml$reporter_outdated %|||% "silent",
script = yaml$script %|||% path_script_default(),
Expand All @@ -101,6 +102,7 @@ tar_config_get_convert <- function(name, value) {
name,
inherits = if_any(is.null(value), NULL, as.character(value)),
garbage_collection = as.logical(value),
level_separation = if_any(is.null(value), NULL, as.numeric(value)),
reporter_make = as.character(value),
reporter_outdated = as.character(value),
script = as.character(value),
Expand Down
15 changes: 15 additions & 0 deletions R/tar_config_set.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
#' ignored if `tar_option_get("controller")` is `NULL`.
#' Independent from the `garbage_collection` argument of [tar_target()],
#' which controls garbage collection on the worker.
#' @param level_separation Argument of [tar_visnetwork()] and [tar_glimpse()]
#' to control the space between hierarchical levels.
#' @param reporter_make Character of length 1, `reporter` argument to
#' [tar_make()] and related functions that run the pipeline.
#' If the argument `NULL`, the setting is not modified.
Expand Down Expand Up @@ -132,6 +134,7 @@
tar_config_set <- function(
inherits = NULL,
garbage_collection = NULL,
level_separation = NULL,
reporter_make = NULL,
reporter_outdated = NULL,
script = NULL,
Expand All @@ -150,6 +153,7 @@ tar_config_set <- function(
tar_assert_scalar(project)
tar_config_assert_inherits(inherits)
tar_config_assert_garbage_collection(garbage_collection)
tar_config_assert_level_separation(level_separation)
tar_config_assert_reporter_make(reporter_make)
tar_config_assert_reporter_outdated(reporter_outdated)
tar_config_assert_script(script)
Expand All @@ -164,6 +168,8 @@ tar_config_set <- function(
yaml[[project]]$inherits <- inherits %|||% yaml[[project]]$inherits
yaml[[project]]$garbage_collection <- garbage_collection %|||%
yaml[[project]]$garbage_collection
yaml[[project]]$level_separation <- level_separation %|||%
yaml[[project]]$level_separation
yaml[[project]]$reporter_make <- reporter_make %|||%
yaml[[project]]$reporter_make
yaml[[project]]$reporter_outdated <- reporter_outdated %|||%
Expand Down Expand Up @@ -206,6 +212,15 @@ tar_config_assert_garbage_collection <- function(garbage_collection) {
tar_assert_none_na(garbage_collection)
}

tar_config_assert_level_separation <- function(level_separation) {
if (is.null(level_separation)) {
return()
}
tar_assert_scalar(level_separation)
tar_assert_dbl(level_separation)
tar_assert_none_na(level_separation)
}

tar_config_assert_reporter_make <- function(reporter_make) {
if (is.null(reporter_make)) {
return()
Expand Down
2 changes: 1 addition & 1 deletion R/tar_glimpse.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ tar_glimpse <- function(
shortcut = FALSE,
allow = NULL,
exclude = ".Random.seed",
level_separation = NULL,
level_separation = targets::tar_config_get("level_separation"),
degree_from = 1L,
degree_to = 1L,
zoom_speed = 1,
Expand Down
2 changes: 1 addition & 1 deletion R/tar_visnetwork.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ tar_visnetwork <- function(
exclude = ".Random.seed",
outdated = TRUE,
label = NULL,
level_separation = NULL,
level_separation = targets::tar_config_get("level_separation"),
degree_from = 1L,
degree_to = 1L,
zoom_speed = 1,
Expand Down
4 changes: 4 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.

14 changes: 14 additions & 0 deletions tests/testthat/test-tar_config_set.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ tar_test("tar_config_set() garbage_collection", {
expect_equal(tar_config_get("garbage_collection"), FALSE)
})

tar_test("tar_config_set() level_separation", {
skip_cran()
expect_false(file.exists("_targets.yaml"))
expect_null(tar_config_get("level_separation"))
tar_config_set(level_separation = 3L)
expect_equal(tar_config_get("level_separation"), 3L)
expect_true(file.exists("_targets.yaml"))
expect_true(any(grepl("level_separation", readLines("_targets.yaml"))))
tar_config_set()
expect_equal(tar_config_get("level_separation"), 3L)
expect_true(file.exists("_targets.yaml"))
unlink("_targets.yaml")
expect_null(tar_config_get("level_separation"))
})

tar_test("tar_config_set() reporter_make", {
skip_cran()
Expand Down

0 comments on commit dcbccfa

Please sign in to comment.