Skip to content

Commit 36f2295

Browse files
committed
merge doc files for tar_rep*()
1 parent 0d94747 commit 36f2295

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+521
-1138
lines changed

Diff for: R/tar_rep.R

+30
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
#' of heavily dynamically-branched workflows:
44
#' <https://books.ropensci.org/targets/dynamic.html#batching>.
55
#' [tar_rep()] replicates a command in strategically sized batches.
6+
#'
7+
#' [tar_rep()] expects unevaluated `name` and `command` arguments
8+
#' (e.g. `tar_rep(name = sim, command = simulate())`)
9+
#' whereas [tar_rep_raw()] expects an evaluated string for `name`
10+
#' and an evaluated expression object for `command`
11+
#' (e.g. `tar_rep_raw(name = "sim", command = quote(simulate()))`).
612
#' @export
713
#' @family branching
814
#' @details `tar_rep()` and `tar_rep_raw()` each create two targets:
@@ -66,10 +72,22 @@
6672
#' To un-batch this nested list, call
6773
#' `tar_read(your_target, recursive = FALSE)`.
6874
#' @inheritParams targets::tar_target
75+
#' @param name Name of the target.
76+
#' [tar_rep()] expects unevaluated `name` and `command` arguments
77+
#' (e.g. `tar_rep(name = sim, command = simulate())`)
78+
#' whereas [tar_rep_raw()] expects an evaluated string for `name`
79+
#' and an evaluated expression object for `command`
80+
#' (e.g. `tar_rep_raw(name = "sim", command = quote(simulate()))`).
6981
#' @param command R code to run multiple times. Must return a list or
7082
#' data frame because `tar_rep()` will try to append new elements/columns
7183
#' `tar_batch` and `tar_rep` to the output to denote the batch
7284
#' and rep-within-batch IDs, respectively.
85+
#'
86+
#' [tar_rep()] expects unevaluated `name` and `command` arguments
87+
#' (e.g. `tar_rep(name = sim, command = simulate())`)
88+
#' whereas [tar_rep_raw()] expects an evaluated string for `name`
89+
#' and an evaluated expression object for `command`
90+
#' (e.g. `tar_rep_raw(name = "sim", command = quote(simulate()))`).
7391
#' @param batches Number of batches. This is also the number of dynamic
7492
#' branches created during `tar_make()`.
7593
#' @param reps Number of replications in each batch. The total number
@@ -113,6 +131,18 @@
113131
#' })
114132
#' targets::tar_make()
115133
#' targets::tar_read(x)
134+
#' targets::tar_script({
135+
#' list(
136+
#' tarchetypes::tar_rep_raw(
137+
#' "x",
138+
#' quote(data.frame(x = sample.int(1e4, 2))),
139+
#' batches = 2,
140+
#' reps = 3
141+
#' )
142+
#' )
143+
#' })
144+
#' targets::tar_make()
145+
#' targets::tar_read(x)
116146
#' })
117147
#' }
118148
tar_rep <- function(

Diff for: R/tar_rep2.R

+46-3
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,83 @@
66
#' <https://books.ropensci.org/targets/dynamic.html#batching>.
77
#' [tar_rep2()] uses dynamic branching to iterate
88
#' over the batches and reps of existing upstream targets.
9+
#'
10+
#' [tar_rep2()] expects unevaluated language for the `name`, `command`,
11+
#' and `...` arguments
12+
#' (e.g. `tar_rep2(name = sim, command = simulate(), data1, data2)`)
13+
#' whereas [tar_rep2_raw()] expects an evaluated string for `name`,
14+
#' an evaluated expression object for `command`,
15+
#' and a character vector for `targets`
16+
#' (e.g.
17+
#' `tar_rep2_raw("sim", quote(simulate(x, y)), targets = c("x', "y"))`).
918
#' @return A new target object to perform batched computation.
1019
#' See the "Target objects" section for background.
1120
#' @inheritSection tar_map Target objects
1221
#' @inheritSection tar_rep Replicate-specific seeds
1322
#' @inheritParams targets::tar_target
1423
#' @inheritParams tar_rep
24+
#' @param name Name of the target.
25+
#' [tar_rep2()] expects unevaluated language for the `name`, `command`,
26+
#' and `...` arguments
27+
#' (e.g. `tar_rep2(name = sim, command = simulate(), data1, data2)`)
28+
#' whereas [tar_rep2_raw()] expects an evaluated string for `name`,
29+
#' an evaluated expression object for `command`,
30+
#' and a character vector for `targets`
31+
#' (e.g.
32+
#' `tar_rep2_raw("sim", quote(simulate(x, y)), targets = c("x', "y"))`).
33+
#' @param command R code to run multiple times. Must return a list or
34+
#' data frame because `tar_rep()` will try to append new elements/columns
35+
#' `tar_batch` and `tar_rep` to the output to denote the batch
36+
#' and rep-within-batch IDs, respectively.
37+
#'
38+
#' [tar_rep2()] expects unevaluated language for the `name`, `command`,
39+
#' and `...` arguments
40+
#' (e.g. `tar_rep2(name = sim, command = simulate(), data1, data2)`)
41+
#' whereas [tar_rep2_raw()] expects an evaluated string for `name`,
42+
#' an evaluated expression object for `command`,
43+
#' and a character vector for `targets`
44+
#' (e.g.
45+
#' `tar_rep2_raw("sim", quote(simulate(x, y)), targets = c("x', "y"))`).
1546
#' @param ... Symbols to name one or more upstream batched targets
1647
#' created by [tar_rep()].
1748
#' If you supply more than one such target, all those targets must have the
1849
#' same number of batches and reps per batch. And they must all return
1950
#' either data frames or lists. List targets must use `iteration = "list"`
2051
#' in [tar_rep()].
52+
#' @param targets Character vector of names of upstream batched targets
53+
#' created by [tar_rep()].
54+
#' If you supply more than one such target, all those targets must have the
55+
#' same number of batches and reps per batch. And they must all return
56+
#' either data frames or lists. List targets must use `iteration = "list"`
57+
#' in [tar_rep()].
2158
#' @examples
2259
#' if (identical(Sys.getenv("TAR_LONG_EXAMPLES"), "true")) {
2360
#' targets::tar_dir({ # tar_dir() runs code from a temporary directory.
2461
#' targets::tar_script({
62+
#' library(tarchetypes)
2563
#' list(
26-
#' tarchetypes::tar_rep(
64+
#' tar_rep(
2765
#' data1,
2866
#' data.frame(value = rnorm(1)),
2967
#' batches = 2,
3068
#' reps = 3
3169
#' ),
32-
#' tarchetypes::tar_rep(
70+
#' tar_rep(
3371
#' data2,
3472
#' list(value = rnorm(1)),
3573
#' batches = 2, reps = 3,
3674
#' iteration = "list" # List iteration is important for batched lists.
3775
#' ),
38-
#' tarchetypes::tar_rep2(
76+
#' tar_rep2(
3977
#' aggregate,
4078
#' data.frame(value = data1$value + data2$value),
4179
#' data1,
4280
#' data2
81+
#' ),
82+
#' tar_rep2_raw(
83+
#' "aggregate2",
84+
#' quote(data.frame(value = data1$value + data2$value)),
85+
#' targets = c("data1", "data2")
4386
#' )
4487
#' )
4588
#' })

Diff for: R/tar_rep2_raw.R

+1-51
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,5 @@
1-
#' @title Dynamic batched computation downstream of [tar_rep()] (raw version).
1+
#' @rdname tar_rep2
22
#' @export
3-
#' @family branching
4-
#' @keywords internal
5-
#' @description Batching is important for optimizing the efficiency
6-
#' of heavily dynamically-branched workflows:
7-
#' <https://books.ropensci.org/targets/dynamic.html#batching>.
8-
#' `tar_rep2_raw()`
9-
#' is just like [tar_rep2()] except it accepts a character
10-
#' of length 1 for `name`, a language object for `command`,
11-
#' and a character vector of the names of the upstream batched targets.
12-
#' @return A new target object to perform batched computation
13-
#' downstream of [tar_rep()].
14-
#' See the "Target objects" section for background.
15-
#' @inheritSection tar_map Target objects
16-
#' @inheritSection tar_rep Replicate-specific seeds
17-
#' @inheritParams targets::tar_target
18-
#' @inheritParams tar_rep
19-
#' @param targets Character vector of names of upstream batched targets
20-
#' created by [tar_rep()].
21-
#' If you supply more than one such target, all those targets must have the
22-
#' same number of batches and reps per batch. And they must all return
23-
#' either data frames or lists. List targets must use `iteration = "list"`
24-
#' in [tar_rep()].
25-
#' @examples
26-
#' if (identical(Sys.getenv("TAR_LONG_EXAMPLES"), "true")) {
27-
#' targets::tar_dir({ # tar_dir() runs code from a temporary directory.
28-
#' targets::tar_script({
29-
#' list(
30-
#' tarchetypes::tar_rep(
31-
#' data1,
32-
#' data.frame(value = rnorm(1)),
33-
#' batches = 2,
34-
#' reps = 3
35-
#' ),
36-
#' tarchetypes::tar_rep(
37-
#' data2,
38-
#' list(value = rnorm(1)),
39-
#' batches = 2, reps = 3,
40-
#' iteration = "list" # List iteration is important for batched lists.
41-
#' ),
42-
#' tarchetypes::tar_rep2_raw(
43-
#' "aggregate",
44-
#' quote(data.frame(value = data1$value + data2$value)),
45-
#' targets = c("data1", "data2")
46-
#' )
47-
#' )
48-
#' })
49-
#' targets::tar_make()
50-
#' targets::tar_read(aggregate)
51-
#' })
52-
#' }
533
tar_rep2_raw <- function(
544
name,
555
command,

Diff for: R/tar_rep_raw.R

+1-65
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,5 @@
1-
#' @title Batched replication with dynamic branching
2-
#' (raw version).
1+
#' @rdname tar_rep
32
#' @export
4-
#' @family branching
5-
#' @description Batching is important for optimizing the efficiency
6-
#' of heavily dynamically-branched workflows:
7-
#' <https://books.ropensci.org/targets/dynamic.html#batching>.
8-
#' [tar_rep_raw()] is just like [tar_rep()] except the
9-
#' name is a character string and the command is a
10-
#' language object.
11-
#' @details `tar_rep_raw()` creates two targets:
12-
#' an upstream local stem
13-
#' with an integer vector of batch ids, and a downstream pattern
14-
#' that maps over the batch ids. (Thus, each batch is a branch.)
15-
#' Each batch/branch replicates the command a certain number of times.
16-
#'
17-
#' Both batches and reps within each batch
18-
#' are aggregated according to the method you specify
19-
#' in the `iteration` argument. If `"list"`, reps and batches
20-
#' are aggregated with `list()`. If `"vector"`,
21-
#' then `vctrs::vec_c()`. If `"group"`, then `vctrs::vec_rbind()`.
22-
#' @inheritSection tar_rep Replicate-specific seeds
23-
#' @return A list of two targets, one upstream and one downstream.
24-
#' The upstream target returns a numeric index of batch ids,
25-
#' and the downstream one dynamically maps over the batch ids
26-
#' to run the command multiple times.
27-
#' If the command returns a list or data frame, then
28-
#' the targets from `tar_rep()` will try to append new elements/columns
29-
#' `tar_batch`, `tar_rep`, and `tar_seed` to the output
30-
#' to denote the batch, rep-within-batch ID, and random number
31-
#' generator seed, respectively.
32-
#'
33-
#' `tar_read(your_target)` (on the downstream target with the actual work)
34-
#' will return a list of lists, where the outer list has one element per
35-
#' batch and each inner list has one element per rep within batch.
36-
#' To un-batch this nested list, call
37-
#' `tar_read(your_target, recursive = FALSE)`.
38-
#' @inheritSection tar_map Target objects
39-
#' @inheritParams targets::tar_target_raw
40-
#' @inheritParams tar_rep
41-
#' @param command Expression object with code to run multiple times.
42-
#' Must return a list or data frame when evaluated.
43-
#' @param batches Number of batches. This is also the number of dynamic
44-
#' branches created during `tar_make()`.
45-
#' @param reps Number of replications in each batch. The total number
46-
#' of replications is `batches * reps`.
47-
#' @param tidy_eval Whether to invoke tidy evaluation
48-
#' (e.g. the `!!` operator from `rlang`) as soon as the target is defined
49-
#' (before `tar_make()`). Applies to the `command` argument.
50-
#' @examples
51-
#' if (identical(Sys.getenv("TAR_LONG_EXAMPLES"), "true")) {
52-
#' targets::tar_dir({ # tar_dir() runs code from a temporary directory.
53-
#' targets::tar_script({
54-
#' list(
55-
#' tarchetypes::tar_rep_raw(
56-
#' "x",
57-
#' expression(data.frame(x = sample.int(1e4, 2))),
58-
#' batches = 2,
59-
#' reps = 3
60-
#' )
61-
#' )
62-
#' })
63-
#' targets::tar_make(callr_function = NULL)
64-
#' targets::tar_read(x)
65-
#' })
66-
#' }
673
tar_rep_raw <- function(
684
name,
695
command,

Diff for: _pkgdown.yml

-2
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ reference:
5656
- title: Dynamic batched replication
5757
contents:
5858
- 'tar_rep'
59-
- 'tar_rep_raw'
6059
- 'tar_rep2'
61-
- 'tar_rep2_raw'
6260
- title: Dynamic batched replication within static branches for data frames
6361
contents:
6462
- 'tar_map_rep'

Diff for: inst/WORDLIST

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Baltagi
1919
batchtools
2020
quosure
2121
Bengtsson
22+
unevaluated
2223
Bioinformatics
2324
Boneri
2425
Bostock

Diff for: man/tar_age.Rd

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

Diff for: man/tar_change.Rd

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

Diff for: man/tar_combine.Rd

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

Diff for: man/tar_combine_raw.Rd

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

0 commit comments

Comments
 (0)