Skip to content

Commit 8d77916

Browse files
committed
sketch parallel aggregation of dynamic branches within static branches
1 parent 896ef2a commit 8d77916

31 files changed

+241
-59
lines changed

R/tar_map_rep.R

+8-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,14 @@
2626
#' @param columns A tidyselect expression to select which columns of `values`
2727
#' to append to the output. Columns already in the target output
2828
#' are not appended.
29-
#' @param combine Logical of length 1, whether to statically combine
30-
#' all the results into a single target downstream.
29+
#' @param combine Logical of length 1, whether to create additional downstream
30+
#' targets to combine the results of static branches.
31+
#' The `values` argument must not be `NULL`
32+
#' for this combining to take effect.
33+
#' If `combine` is `TRUE` and `values` is not `NULL`,
34+
#' then separate targets aggregate all dynamic branches within each
35+
#' static branch, and then a final target combines all
36+
#' the static branches together.
3137
#' @examples
3238
#' if (identical(Sys.getenv("TAR_LONG_EXAMPLES"), "true")) {
3339
#' targets::tar_dir({ # tar_dir() runs code from a temporary directory.

R/tar_map_rep_raw.R

+55-8
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ tar_map_rep_raw <- function(
112112
is.null(values),
113113
target_dynamic,
114114
do.call(
115-
tar_map,
115+
what = tar_map,
116116
args = list(
117117
target_dynamic,
118118
values = values,
@@ -126,12 +126,58 @@ tar_map_rep_raw <- function(
126126
if (!unlist && is.list(target_static)) {
127127
target_static <- target_static[[1L]]
128128
}
129-
target_combine <- if_any(
130-
is.null(values) || !combine,
131-
NULL,
132-
tar_combine_raw(
129+
target_combine <- NULL
130+
target_combine_dynamic <- NULL
131+
if (combine && !is.null(values)) {
132+
expr <- substitute(
133+
targets::tar_target_raw(
134+
name = paste0(name, "_combine"),
135+
command = as.symbol(name),
136+
packages = packages,
137+
library = library,
138+
format = format,
139+
repository = repository,
140+
iteration = "vector",
141+
error = error,
142+
memory = memory,
143+
garbage_collection = garbage_collection,
144+
deployment = deployment,
145+
priority = priority,
146+
resources = resources,
147+
storage = storage,
148+
retrieval = retrieval,
149+
cue = cue,
150+
description = description
151+
),
152+
env = list(
153+
packages = packages,
154+
library = library,
155+
format = format,
156+
repository = repository,
157+
iteration = "vector",
158+
error = error,
159+
memory = memory,
160+
garbage_collection = garbage_collection,
161+
deployment = deployment,
162+
priority = priority,
163+
resources = resources,
164+
storage = storage,
165+
retrieval = retrieval,
166+
cue = cue,
167+
description = description
168+
)
169+
)
170+
target_combine_dynamic <- tar_eval_raw(
171+
expr = expr,
172+
values = list(name = map_chr(target_static, ~.x$settings$name))
173+
)
174+
names(target_combine_dynamic) <- map_chr(
175+
target_combine_dynamic,
176+
~.x$settings$name
177+
)
178+
target_combine <- tar_combine_raw(
133179
name = name,
134-
target_static,
180+
target_combine_dynamic,
135181
command = tar_map_combine_command,
136182
use_names = TRUE,
137183
packages = character(0),
@@ -141,15 +187,16 @@ tar_map_rep_raw <- function(
141187
error = error,
142188
memory = memory,
143189
garbage_collection = garbage_collection,
144-
deployment = "main",
190+
deployment = deployment,
145191
priority = priority,
146192
cue = cue,
147193
description = description
148194
)
149-
)
195+
}
150196
out <- list(
151197
batch_index = target_batch,
152198
static_branches = target_static,
199+
combine_dynamic = target_combine_dynamic,
153200
combine = target_combine
154201
)
155202
if (unlist) {

man/tar_age.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/tar_change.Rd

+10-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/tar_combine.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/tar_download.Rd

+10-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/tar_file_read.Rd

+10-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/tar_files.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/tar_files_input.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/tar_force.Rd

+10-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/tar_formats.Rd

+10-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/tar_formats_superseded.Rd

+10-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/tar_group_by.Rd

+10-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/tar_group_count.Rd

+10-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/tar_group_select.Rd

+10-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)