Skip to content

Commit 1c6f39d

Browse files
committed
Fix #191
1 parent 92cdae0 commit 1c6f39d

Some content is hidden

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

67 files changed

+1119
-4455
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Description: Function-oriented Make-like declarative pipelines for
99
reproducible pipelines concisely and compactly.
1010
The methods in this package were influenced by the 'drake' R package
1111
by Will Landau (2018) <doi:10.21105/joss.00550>.
12-
Version: 0.9.1.9000
12+
Version: 0.9.1.9001
1313
License: MIT + file LICENSE
1414
URL: https://docs.ropensci.org/tarchetypes/, https://github.com/ropensci/tarchetypes
1515
BugReports: https://github.com/ropensci/tarchetypes/issues

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export(tar_map2)
8383
export(tar_map2_count)
8484
export(tar_map2_count_raw)
8585
export(tar_map2_group)
86+
export(tar_map2_raw)
8687
export(tar_map2_run)
8788
export(tar_map2_run_rep)
8889
export(tar_map2_size)

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
# tarchetypes 0.9.1.9000 (development)
1+
# tarchetypes 0.9.1.9001 (development)
22

33
* Add a `delimiter` argument to `tar_map()` etc. for customizing separators in target names (#177, @psychelzh).
44
* Add "raw" hook functions (#185, @multimeric).
55
* Add `tar_assign()` (#186, https://github.com/ropensci/targets/issues/1309, @hadley).
6+
* Merge help files of "_raw" functions (#191, @hadley).
67

78
# tarchetypes 0.9.0
89

R/tar_cue_age.R

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,32 @@
66
#' The age of the target is determined by `targets::tar_timestamp()`,
77
#' and the way the time stamp is calculated is explained
88
#' in the Details section of the help file of that function.
9+
#'
10+
#' `tar_cue_age()` expects an unevaluated symbol for the `name`
11+
#' argument, whereas `tar_cue_age_raw()` expects a character string
12+
#' for `name`.
913
#' @details `tar_cue_age()` uses the time stamps from `tar_meta()$time`.
1014
#' If no time stamp is recorded, the cue defaults to the ordinary
1115
#' invalidation rules (i.e. `mode = "thorough"` in `targets::tar_cue()`).
1216
#' @inheritSection tar_age Dynamic branches at regular time intervals
1317
#' @return A cue object. See the "Cue objects" section for background.
1418
#' @inheritSection tar_cue_force Cue objects
15-
#' @inheritParams tar_cue_age_raw
16-
#' @param name Symbol, name of the target.
19+
#' @inheritSection tar_cue_force Cue objects
20+
#' @inheritParams targets::tar_cue
21+
#' @param name Name of the target.
22+
#' `tar_cue_age()` expects an unevaluated symbol for the `name`
23+
#' argument, whereas `tar_cue_age_raw()` expects a character string
24+
#' for `name`.
25+
#' @param age A `difftime` object of length 1, such as
26+
#' `as.difftime(3, units = "days")`. If the target's output data
27+
#' files are older than `age` (according to the most recent
28+
#' time stamp over all the target's output files)
29+
#' then the target will rerun.
30+
#' On the other hand, if at least one data file is
31+
#' younger than `Sys.time() - age`, then the ordinary
32+
#' invalidation rules apply, and the target may or not rerun.
33+
#' If you want to force the target to run every 3 days,
34+
#' for example, set `age = as.difftime(3, units = "days")`.
1735
#' @examples
1836
#' if (identical(Sys.getenv("TAR_LONG_EXAMPLES"), "true")) {
1937
#' targets::tar_dir({ # tar_dir() runs code from a temporary directory.

R/tar_cue_age_raw.R

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,5 @@
1-
#' @title Cue to run a target when the last run reaches a certain age
2-
#' (raw version)
1+
#' @rdname tar_cue_age
32
#' @export
4-
#' @family cues
5-
#' @description `tar_cue_age_raw()` acts like `tar_cue_age()`
6-
#' except the `name` argument is a character string,
7-
#' not a symbol. `tar_cue_age_raw()` creates a cue object to
8-
#' rerun a target if the most recent output data becomes old enough.
9-
#' The age of the target is determined by `targets::tar_timestamp()`,
10-
#' and the way the time stamp is calculated is explained
11-
#' in the Details section of the help file of that function.
12-
#' @details `tar_cue_age_raw()` uses the time stamps from `tar_meta()$time`.
13-
#' If no time stamp is recorded, the cue defaults to the ordinary
14-
#' invalidation rules (i.e. `mode = "thorough"` in `targets::tar_cue()`).
15-
#' @inheritSection tar_age Dynamic branches at regular time intervals
16-
#' @return A cue object. See the "Cue objects" section for background.
17-
#' @inheritSection tar_cue_force Cue objects
18-
#' @inheritParams targets::tar_cue
19-
#' @param name Character of length 1, name of the target.
20-
#' @param age A `difftime` object of length 1, such as
21-
#' `as.difftime(3, units = "days")`. If the target's output data
22-
#' files are older than `age` (according to the most recent
23-
#' time stamp over all the target's output files)
24-
#' then the target will rerun.
25-
#' On the other hand, if at least one data file is
26-
#' younger than `Sys.time() - age`, then the ordinary
27-
#' invalidation rules apply, and the target may or not rerun.
28-
#' If you want to force the target to run every 3 days,
29-
#' for example, set `age = as.difftime(3, units = "days")`.
30-
#' @examples
31-
#' if (identical(Sys.getenv("TAR_LONG_EXAMPLES"), "true")) {
32-
#' targets::tar_dir({ # tar_dir() runs code from a temporary directory.
33-
#' targets::tar_script({
34-
#' library(tarchetypes)
35-
#' list(
36-
#' targets::tar_target(
37-
#' data,
38-
#' data.frame(x = seq_len(26)),
39-
#' cue = tarchetypes::tar_cue_age_raw(
40-
#' name = "data",
41-
#' age = as.difftime(0.5, units = "secs")
42-
#' )
43-
#' )
44-
#' )
45-
#' })
46-
#' targets::tar_make()
47-
#' Sys.sleep(0.6)
48-
#' targets::tar_make()
49-
#' })
50-
#' }
513
tar_cue_age_raw <- function(
524
name,
535
age,

R/tar_eval.R

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,24 @@
44
#' @description Loop over a grid of values, create an expression object
55
#' from each one, and then evaluate that expression.
66
#' Helps with general metaprogramming.
7+
#'
8+
#' [tar_eval()] expects an unevaluated expression for
9+
#' the `expr` object, whereas [tar_eval_raw()] expects an
10+
#' evaluated expression object.
711
#' @return A list of return values from the generated expression objects.
812
#' Often, these values are target objects.
913
#' See the "Target objects" section for background
1014
#' on target objects specifically.
1115
#' @inheritSection tar_map Target objects
12-
#' @inheritParams tar_eval_raw
16+
#' @inheritParams tar_sub
1317
#' @param expr Starting expression. Values are iteratively substituted
1418
#' in place of symbols in `expr` to create each new expression,
1519
#' and then each new expression is evaluated.
20+
#'
21+
#' [tar_eval()] expects an unevaluated expression for
22+
#' the `expr` object, whereas [tar_eval_raw()] expects an
23+
#' evaluated expression object.
24+
#' @param envir Environment in which to evaluate the new expressions.
1625
#' @examples
1726
#' # tar_map() is incompatible with tar_render() because the latter
1827
#' # operates on preexisting tar_target() objects. By contrast,
@@ -27,6 +36,7 @@
2736
#' path <- tempfile()
2837
#' file.create(path)
2938
#' str(tar_eval(tar_render(name, path), values = values))
39+
#' str(tar_eval_raw(quote(tar_render(name, path)), values = values))
3040
#' # So in your _targets.R file, you can define a pipeline like as below.
3141
#' # Just make sure to set a unique name for each target
3242
#' # (which tar_map() does automatically).

R/tar_eval_raw.R

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,5 @@
1-
#' @title Evaluate multiple expressions created with symbol substitution
2-
#' (raw version).
1+
#' @rdname tar_eval
32
#' @export
4-
#' @family Metaprogramming utilities
5-
#' @description Loop over a grid of values, create an expression object
6-
#' from each one, and then evaluate that expression.
7-
#' Helps with general metaprogramming. Unlike [tar_sub()],
8-
#' which quotes the `expr` argument, `tar_sub_raw()` assumes `expr`
9-
#' is an expression object.
10-
#' @return A list of return values from evaluating the expression objects.
11-
#' Often, these values are target objects.
12-
#' See the "Target objects" section for background
13-
#' on target objects specifically.
14-
#' @inheritSection tar_map Target objects
15-
#' @inheritParams tar_sub_raw
16-
#' @param expr Expression object with the starting expression.
17-
#' Values are iteratively substituted
18-
#' in place of symbols in `expr` to create each new expression,
19-
#' and then each expression is evaluated.
20-
#' @param envir Environment in which to evaluate the new expressions.
21-
#' @examples
22-
#' # tar_map() is incompatible with tar_render() because the latter
23-
#' # operates on preexisting tar_target() objects. By contrast,
24-
#' # tar_eval_raw() and tar_sub_raw() iterate over code farther upstream.
25-
#' values <- list(
26-
#' name = lapply(c("name1", "name2"), as.symbol),
27-
#' file = c("file1.Rmd", "file2.Rmd")
28-
#' )
29-
#' tar_sub_raw(quote(list(name, file)), values = values)
30-
#' tar_sub_raw(quote(tar_render(name, file)), values = values)
31-
#' path <- tempfile()
32-
#' file.create(path)
33-
#' str(tar_eval_raw(quote(tar_render(name, path)), values = values))
34-
#' # So in your _targets.R file, you can define a pipeline like as below.
35-
#' # Just make sure to set a unique name for each target
36-
#' # (which tar_map() does automatically).
37-
#' values <- list(
38-
#' name = lapply(c("name1", "name2"), as.symbol),
39-
#' file = c(path, path)
40-
#' )
41-
#' list(
42-
#' tar_eval_raw(quote(tar_render(name, file)), values = values)
43-
#' )
443
tar_eval_raw <- function(expr, values, envir = parent.frame()) {
454
targets::tar_assert_lang(expr)
465
assert_values_list(values)

R/tar_hook_before.R

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,43 @@
22
#' @export
33
#' @family hooks
44
#' @description Prepend R code to the commands of multiple targets.
5+
#' `tar_hook_before()` expects unevaluated expressions for the `hook` and
6+
#' `names` arguments, whereas `tar_hook_before_raw()` expects
7+
#' evaluated expression objects.
58
#' @return A flattened list of target objects with the hooks applied.
69
#' Even if the input target list had a nested structure,
710
#' the return value is a simple list where each element is a target object.
811
#' All hook functions remove the nested structure of the input target list.
912
#' @inheritSection tar_map Target objects
1013
#' @inheritParams tar_hook_before_raw
11-
#' @param hook R code to insert. When you supply code to this argument,
12-
#' the code is quoted (not evaluated) so there is no need
13-
#' to wrap it in `quote()`, `expression()`, or similar.
14+
#' @param hook R code to insert.
15+
#' `tar_hook_before()` expects unevaluated expressions for the `hook` and
16+
#' `names` arguments, whereas `tar_hook_before_raw()` expects
17+
#' evaluated expression objects.
1418
#' @param names Name of targets in the target list
15-
#' to apply the hook. Supplied with `tidyselect` helpers like
19+
#' to apply the hook. Supplied using `tidyselect` helpers like
1620
#' [starts_with()], as in `names = starts_with("your_prefix_")`.
1721
#' Set to `NULL` to include all targets supplied to the `targets` argument.
1822
#' Targets not included in `names` still remain in the target list,
1923
#' but they are not modified because the hook does not apply to them.
24+
#'
25+
#' The regular hook functions expects unevaluated expressions for the `hook`
26+
#' and `names` arguments, whereas the `"_raw"` versions expect
27+
#' evaluated expression objects.
28+
#' @param set_deps Logical of length 1, whether to refresh the dependencies
29+
#' of each modified target by scanning the newly generated
30+
#' target commands for dependencies. If `FALSE`, then the target will
31+
#' keep the original set of dependencies it had before the hook.
32+
#' Set to `NULL` to include all targets supplied to the `targets` argument.
33+
#' `TRUE` is recommended for nearly all situations. Only use `FALSE`
34+
#' if you have a specialized use case and you know what you are doing.
35+
#' @param envir Optional environment to construct the quosure for the `names`
36+
#' argument to select names.
37+
#' @param targets A list of target objects. The input target list
38+
#' can be arbitrarily nested, but it must consist entirely of target
39+
#' objects. In addition, the return value is a simple list
40+
#' where each element is a target object.
41+
#' All hook functions remove the nested structure of the input target list.
2042
#' @examples
2143
#' if (identical(Sys.getenv("TAR_LONG_EXAMPLES"), "true")) {
2244
#' targets::tar_dir({ # tar_dir() runs code from a temporary directory.
@@ -38,6 +60,23 @@
3860
#' })
3961
#' targets::tar_manifest(fields = command)
4062
#' })
63+
#' # With tar_hook_before_raw():
64+
#' targets::tar_script({
65+
#' targets <- list(
66+
#' # Nested target lists work with hooks.
67+
#' list(
68+
#' targets::tar_target(x1, task1()),
69+
#' targets::tar_target(x2, task2(x1))
70+
#' ),
71+
#' targets::tar_target(x3, task3(x2)),
72+
#' targets::tar_target(y1, task4(x3))
73+
#' )
74+
#' tarchetypes::tar_hook_before_raw(
75+
#' targets = targets,
76+
#' hook = quote(print("Running hook.")),
77+
#' names = quote(starts_with("x"))
78+
#' )
79+
#' })
4180
#' }
4281
tar_hook_before <- function(
4382
targets,

R/tar_hook_before_raw.R

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,5 @@
1-
#' @title Hook to prepend code (raw version)
1+
#' @rdname tar_hook_before
22
#' @export
3-
#' @family hooks
4-
#' @description Prepend R code to the commands of multiple targets.
5-
#' Like [tar_hook_before()] except that the `hook` and `names`
6-
#' arguments are already pre-quoted language objects.
7-
#' @return A flattened list of target objects with the hooks applied.
8-
#' Even if the input target list had a nested structure,
9-
#' the return value is a simple list where each element is a target object.
10-
#' All hook functions remove the nested structure of the input target list.
11-
#' @inheritSection tar_map Target objects
12-
#' @param targets A list of target objects. The input target list
13-
#' can be arbitrarily nested, but it must consist entirely of target
14-
#' objects. In addition, the return value is a simple list
15-
#' where each element is a target object.
16-
#' All hook functions remove the nested structure of the input target list.
17-
#' @param hook A pre-quoted language object with R code to insert.
18-
#' @param names Name of targets in the target list
19-
#' to apply the hook. Supplied as a language object with a
20-
#' `tidyselect` expression: for example, `names = quote(starts_with("x_"))`.
21-
#' Targets not included in `names` still remain in the target list,
22-
#' but they are not modified because the hook does not apply to them.
23-
#' @param set_deps Logical of length 1, whether to refresh the dependencies
24-
#' of each modified target by scanning the newly generated
25-
#' target commands for dependencies. If `FALSE`, then the target will
26-
#' keep the original set of dependencies it had before the hook.
27-
#' Set to `NULL` to include all targets supplied to the `targets` argument.
28-
#' `TRUE` is recommended for nearly all situations. Only use `FALSE`
29-
#' if you have a specialized use case and you know what you are doing.
30-
#' @param envir Optional environment to construct the quosure for the `names`
31-
#' argument to select names.
32-
#' @examples
33-
#' if (identical(Sys.getenv("TAR_LONG_EXAMPLES"), "true")) {
34-
#' targets::tar_dir({ # tar_dir() runs code from a temporary directory.
35-
#' targets::tar_script({
36-
#' targets <- list(
37-
#' # Nested target lists work with hooks.
38-
#' list(
39-
#' targets::tar_target(x1, task1()),
40-
#' targets::tar_target(x2, task2(x1))
41-
#' ),
42-
#' targets::tar_target(x3, task3(x2)),
43-
#' targets::tar_target(y1, task4(x3))
44-
#' )
45-
#' tarchetypes::tar_hook_before_raw(
46-
#' targets = targets,
47-
#' hook = quote(print("Running hook.")),
48-
#' names = quote(starts_with("x"))
49-
#' )
50-
#' })
51-
#' targets::tar_manifest(fields = command)
52-
#' })
53-
#' }
543
tar_hook_before_raw <- function(
554
targets,
565
hook,

R/tar_hook_inner.R

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#' @family hooks
44
#' @description In the command of each target, wrap each mention of
55
#' each dependency target in an arbitrary R expression.
6+
#'
7+
#' `tar_hook_inner()` expects unevaluated expressions for the `hook` and
8+
#' `names` arguments, whereas `tar_hook_inner_raw()` expects
9+
#' evaluated expression objects.
610
#' @details The expression you supply to `hook`
711
#' must contain the special placeholder symbol `.x`
812
#' so `tar_hook_inner()` knows where to insert the original command
@@ -17,8 +21,10 @@
1721
#' The hook must contain the special placeholder symbol `.x`
1822
#' so `tar_hook_inner()` knows where to insert the code to wrap
1923
#' mentions of dependencies.
20-
#' The hook code is quoted (not evaluated) so there is no need
21-
#' to wrap it in `quote()`, `expression()`, or similar.
24+
#'
25+
#' `tar_hook_inner()` expects unevaluated expressions for the `hook` and
26+
#' `names` arguments, whereas `tar_hook_inner_raw()` expects
27+
#' evaluated expression objects.
2228
#' @param names_wrap Names of targets to wrap with the hook
2329
#' where they appear as dependencies in the commands of other targets.
2430
#' Use `tidyselect` helpers like [starts_with()], as in
@@ -43,6 +49,23 @@
4349
#' )
4450
#' })
4551
#' targets::tar_manifest(fields = command)
52+
#' # With tar_hook_inner_raw():
53+
#' targets::tar_script({
54+
#' targets <- list(
55+
#' # Nested target lists work with hooks.
56+
#' list(
57+
#' targets::tar_target(x1, task1()),
58+
#' targets::tar_target(x2, task2(x1))
59+
#' ),
60+
#' targets::tar_target(x3, task3(x2, x1)),
61+
#' targets::tar_target(y1, task4(x3))
62+
#' )
63+
#' tarchetypes::tar_hook_inner_raw(
64+
#' targets = targets,
65+
#' hook = quote(fun(.x)),
66+
#' names = quote(starts_with("x"))
67+
#' )
68+
#' })
4669
#' })
4770
#' }
4871
tar_hook_inner <- function(

0 commit comments

Comments
 (0)