Skip to content

Commit

Permalink
tar_outdated() sensible defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Jan 2, 2025
1 parent 53d5200 commit 4e8e34b
Show file tree
Hide file tree
Showing 18 changed files with 138 additions and 59 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.9.1.9004
Version: 1.9.1.9005
License: MIT + file LICENSE
URL: https://docs.ropensci.org/targets/, https://github.com/ropensci/targets
BugReports: https://github.com/ropensci/targets/issues
Expand Down
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# targets 1.9.1.9004
# targets 1.9.1.9005

* Use a more lookup-efficient data structure for `tar_runtime$file_info` (#1398).
* Fall back on vector aggregation without names (#1401, @guglicap).
* Reduce overhead in `tar_outdated()` by at least 33% (#1408).
* Speed up representation of file sizes in metadata (#1408). This may slow down the next call to `tar_make()` in existing pipelines, but the new file size format will update in the metadata during that call, and then `tar_make()` should be faster after that.
* Add a new `"forecast_interactive"` reporter to `tar_outdated()` to choose `"forecast"` for interactive sessions and `"silent"` for non-interactive ones.
* Add a new `seconds_reporter_outdated` argument to `tar_config_set()` with a default of 0.5 to control the time interval of the reporter of `tar_outdated()` and other passive algorithm functions.
* Remove target descriptions from the default labels of graph visualizations.

# targets 1.9.1

Expand Down
2 changes: 1 addition & 1 deletion R/class_outdated.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ outdated_init <- function(
reporter = "silent",
seconds_meta_append = 0,
seconds_meta_upload = 15,
seconds_reporter = 0
seconds_reporter = 0.5
) {
outdated_new(
pipeline = pipeline,
Expand Down
18 changes: 12 additions & 6 deletions R/class_sitrep.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ sitrep_init <- function(
names = NULL,
shortcut = FALSE,
queue = "sequential",
reporter = "silent"
reporter = "silent",
seconds_reporter = 0.5
) {
sitrep_new(
pipeline = pipeline,
meta = meta,
names = names,
shortcut = shortcut,
queue = queue,
reporter = reporter
reporter = reporter,
seconds_reporter = seconds_reporter
)
}

Expand All @@ -22,15 +24,17 @@ sitrep_new <- function(
names = NULL,
shortcut = shortcut,
queue = NULL,
reporter = NULL
reporter = NULL,
seconds_reporter = NULL
) {
sitrep_class$new(
pipeline = pipeline,
meta = meta,
names = names,
shortcut = shortcut,
queue = queue,
reporter = reporter
reporter = reporter,
seconds_reporter = seconds_reporter
)
}

Expand All @@ -49,15 +53,17 @@ sitrep_class <- R6::R6Class(
names = NULL,
shortcut = NULL,
queue = NULL,
reporter = NULL
reporter = NULL,
seconds_reporter = NULL
) {
super$initialize(
pipeline = pipeline,
meta = meta,
names = names,
shortcut = shortcut,
queue = queue,
reporter = reporter
reporter = reporter,
seconds_reporter = seconds_reporter
)
self$sitrep <- new.env(parent = emptyenv())
},
Expand Down
6 changes: 4 additions & 2 deletions R/tar_config_get.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,16 @@ tar_config_get_project <- function(name, yaml) {
inherits = yaml$inherits,
as_job = yaml$as_job %|||% FALSE,
garbage_collection = yaml$garbage_collection,
label = yaml$label %|||% "description",
label = yaml$label %|||% character(0L),
label_width = yaml$label_width %|||% 30L,
level_separation = yaml$level_separation,
reporter_make = yaml$reporter_make %|||% "verbose",
reporter_outdated = yaml$reporter_outdated %|||% "silent",
reporter_outdated = yaml$reporter_outdated %|||% "forecast_interactive",
script = yaml$script %|||% path_script_default(),
seconds_meta_append = yaml$seconds_meta_append %|||% 0,
seconds_meta_upload = yaml$seconds_meta_upload %|||% 15,
seconds_reporter = yaml$seconds_reporter %|||% 0,
seconds_reporter_outdated = yaml$seconds_reporter_outdated %|||% 0.25,
seconds_interval = yaml$seconds_interval,
shortcut = yaml$shortcut %|||% FALSE,
store = yaml$store %|||% path_store_default(),
Expand All @@ -120,6 +121,7 @@ tar_config_get_convert <- function(name, value) {
seconds_meta_append = as.numeric(value),
seconds_meta_upload = as.numeric(value),
seconds_reporter = as.numeric(value),
seconds_reporter_outdated = as.numeric(value),
seconds_interval = if_any(is.null(value), NULL, as.numeric(value)),
shortcut = as.logical(value),
store = as.character(value),
Expand Down
21 changes: 17 additions & 4 deletions R/tar_config_set.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,13 @@
#' @param seconds_reporter Argument of [tar_make()], [tar_make_clustermq()],
#' and [tar_make_future()]. Positive numeric of length 1 with the minimum
#' number of seconds between times when the reporter prints progress
#' messages to the R console.
#' messages to the R console (for the aforementioned
#' [tar_make()]-like functions only).
#' @param seconds_reporter_outdated Argument of [tar_outdated()]
#' and other related functions that do not run the pipeline.
#' Positive numeric of length 1 with the minimum
#' number of seconds between times when the reporter prints progress
#' messages to the R console for [tar_outdated()].
#' @param shortcut logical of length 1, default `shortcut` argument
#' to [tar_make()] and related functions.
#' If the argument `NULL`, the setting is not modified.
Expand Down Expand Up @@ -177,6 +183,7 @@ tar_config_set <- function(
seconds_meta_append = NULL,
seconds_meta_upload = NULL,
seconds_reporter = NULL,
seconds_reporter_outdated = NULL,
seconds_interval = NULL,
store = NULL,
shortcut = NULL,
Expand All @@ -203,6 +210,7 @@ tar_config_set <- function(
tar_config_assert_seconds_meta_append(seconds_meta_append)
tar_config_assert_seconds_meta_upload(seconds_meta_upload)
tar_config_assert_seconds_reporter(seconds_reporter)
tar_config_assert_seconds_reporter_outdated(seconds_reporter_outdated)
tar_config_assert_seconds_interval(seconds_interval)
tar_config_assert_shortcut(shortcut)
tar_config_assert_store(store)
Expand All @@ -226,8 +234,10 @@ tar_config_set <- function(
yaml[[project]]$seconds_meta_append
yaml[[project]]$seconds_meta_upload <- seconds_meta_upload %|||%
yaml[[project]]$seconds_meta_upload
yaml[[project]]$seconds_reporter <- seconds_reporter %|||%
yaml[[project]]$seconds_reporter
yaml[[project]][["seconds_reporter"]] <- seconds_reporter %|||%
yaml[[project]][["seconds_reporter"]]
yaml[[project]]$seconds_reporter_outdated <- seconds_reporter_outdated %|||%
yaml[[project]]$seconds_reporter_outdated
yaml[[project]]$seconds_interval <- seconds_interval %|||%
yaml[[project]]$seconds_interval
yaml[[project]]$shortcut <- shortcut %|||% yaml[[project]]$shortcut
Expand Down Expand Up @@ -372,6 +382,9 @@ tar_config_assert_seconds_reporter <- function(seconds_reporter) {
tar_assert_ge(seconds_reporter, 0)
}

tar_config_assert_seconds_reporter_outdated <-
tar_config_assert_seconds_reporter

tar_config_assert_shortcut <- function(shortcut) {
if (is.null(shortcut)) {
return()
Expand Down Expand Up @@ -418,7 +431,7 @@ tar_reporters_make <- function() {
}

tar_reporters_outdated <- function() {
c("forecast", "silent")
c("forecast_interactive", "forecast", "silent")
}

tar_config_read_yaml <- function(config) {
Expand Down
3 changes: 2 additions & 1 deletion R/tar_mermaid.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ tar_mermaid <- function(
legend = TRUE,
color = TRUE,
reporter = targets::tar_config_get("reporter_outdated"),
seconds_reporter = targets::tar_config_get("seconds_reporter"),
seconds_reporter = targets::tar_config_get("seconds_reporter_outdated"),
callr_function = callr::r,
callr_arguments = targets::tar_callr_args_default(callr_function),
envir = parent.frame(),
Expand All @@ -72,6 +72,7 @@ tar_mermaid <- function(
tar_assert_scalar(legend)
tar_assert_scalar(color)
tar_config_assert_reporter_outdated(reporter)
reporter <- tar_outdated_reporter(reporter)
tar_assert_callr_function(callr_function)
tar_assert_list(callr_arguments, "callr_arguments mut be a list.")
tar_assert_dbl(seconds_reporter)
Expand Down
3 changes: 2 additions & 1 deletion R/tar_network.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ tar_network <- function(
exclude = NULL,
outdated = TRUE,
reporter = targets::tar_config_get("reporter_outdated"),
seconds_reporter = targets::tar_config_get("seconds_reporter"),
seconds_reporter = targets::tar_config_get("seconds_reporter_outdated"),
callr_function = callr::r,
callr_arguments = targets::tar_callr_args_default(callr_function, reporter),
envir = parent.frame(),
Expand All @@ -92,6 +92,7 @@ tar_network <- function(
force(envir)
tar_assert_lgl(targets_only)
tar_config_assert_reporter_outdated(reporter)
reporter <- tar_outdated_reporter(reporter)
tar_assert_callr_function(callr_function)
tar_assert_list(callr_arguments)
tar_assert_dbl(seconds_reporter)
Expand Down
22 changes: 18 additions & 4 deletions R/tar_outdated.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@
#' created by running the target script file (default: `_targets.R`).
#' @param reporter Character of length 1, name of the reporter to user.
#' Controls how messages are printed as targets are checked. Choices:
#' * `"silent"`: print nothing.
#' * `"forecast"`: print running totals of the checked and outdated
#' targets found so far.
#' * `"forecast_interactive"` (default): use the forecast reporter if the
#' session is interactive (see [base::interactive()]),
#' otherwise use the silent reporter.
#' * `"silent"`: print nothing.
#' * `"forecast"`: print running totals of the checked and outdated
#' targets found so far.
#' @inheritParams tar_validate
#' @examples
#' if (identical(Sys.getenv("TAR_EXAMPLES"), "true")) { # for CRAN
Expand All @@ -64,7 +67,7 @@ tar_outdated <- function(
branches = FALSE,
targets_only = TRUE,
reporter = targets::tar_config_get("reporter_outdated"),
seconds_reporter = targets::tar_config_get("seconds_reporter"),
seconds_reporter = targets::tar_config_get("seconds_reporter_outdated"),
seconds_interval = targets::tar_config_get("seconds_interval"),
callr_function = callr::r,
callr_arguments = targets::tar_callr_args_default(callr_function, reporter),
Expand All @@ -78,6 +81,7 @@ tar_outdated <- function(
tar_assert_lgl(shortcut)
tar_assert_lgl(branches)
tar_assert_flag(reporter, tar_reporters_outdated())
reporter <- tar_outdated_reporter(reporter)
tar_assert_dbl(seconds_reporter)
tar_assert_scalar(seconds_reporter)
tar_assert_none_na(seconds_reporter)
Expand Down Expand Up @@ -159,3 +163,13 @@ tar_outdated_globals <- function(pipeline, meta) {
different[is.na(different)] <- TRUE
comparison$name[different]
}

tar_outdated_reporter <- function(reporter) {
if (identical(reporter, "forecast_interactive")) {
reporter <- if_any(
interactive(),
"forecast",
"silent"
)
}
}
11 changes: 8 additions & 3 deletions R/tar_sitrep.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ tar_sitrep <- function(
fields = NULL,
shortcut = targets::tar_config_get("shortcut"),
reporter = targets::tar_config_get("reporter_outdated"),
seconds_reporter = targets::tar_config_get("seconds_reporter_outdated"),
callr_function = callr::r,
callr_arguments = targets::tar_callr_args_default(callr_function, reporter),
envir = parent.frame(),
Expand All @@ -110,6 +111,7 @@ tar_sitrep <- function(
tar_assert_scalar(shortcut)
tar_assert_lgl(shortcut)
tar_assert_flag(reporter, tar_reporters_outdated())
reporter <- tar_outdated_reporter(reporter)
tar_assert_callr_function(callr_function)
tar_assert_list(callr_arguments)
tar_message_meta(store = store)
Expand All @@ -118,7 +120,8 @@ tar_sitrep <- function(
names_quosure = rlang::enquo(names),
shortcut = shortcut,
fields_quosure = rlang::enquo(fields),
reporter = reporter
reporter = reporter,
seconds_reporter = seconds_reporter
)
callr_outer(
targets_function = tar_sitrep_inner,
Expand All @@ -138,7 +141,8 @@ tar_sitrep_inner <- function(
names_quosure,
shortcut,
fields_quosure,
reporter
reporter,
seconds_reporter
) {
names_all <- pipeline_get_names(pipeline)
names <- tar_tidyselect_eval(names_quosure, names_all)
Expand All @@ -148,7 +152,8 @@ tar_sitrep_inner <- function(
names = names,
shortcut = shortcut,
queue = "sequential",
reporter = reporter
reporter = reporter,
seconds_reporter = seconds_reporter
)
sitrep$run()
out <- tibble::as_tibble(data.table::rbindlist(as.list(sitrep$sitrep)))
Expand Down
3 changes: 2 additions & 1 deletion R/tar_visnetwork.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ tar_visnetwork <- function(
zoom_speed = 1,
physics = FALSE,
reporter = targets::tar_config_get("reporter_outdated"),
seconds_reporter = targets::tar_config_get("seconds_reporter"),
seconds_reporter = targets::tar_config_get("seconds_reporter_outdated"),
callr_function = callr::r,
callr_arguments = targets::tar_callr_args_default(callr_function),
envir = parent.frame(),
Expand Down Expand Up @@ -76,6 +76,7 @@ tar_visnetwork <- function(
tar_assert_lgl(physics)
tar_assert_scalar(physics)
tar_config_assert_reporter_outdated(reporter)
reporter <- tar_outdated_reporter(reporter)
tar_assert_dbl(seconds_reporter)
tar_assert_scalar(seconds_reporter)
tar_assert_none_na(seconds_reporter)
Expand Down
10 changes: 9 additions & 1 deletion man/tar_config_set.Rd

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

13 changes: 7 additions & 6 deletions man/tar_mermaid.Rd

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

Loading

0 comments on commit 4e8e34b

Please sign in to comment.