"Plucking" targets generated by static and dynamic branch for individual consideration #419
Replies: 1 comment 3 replies
-
library(targets)
tar_script({
library(targets)
library(tarchetypes)
library(tibble)
method1 <- function(label, seed) {
tibble(method = 1, label = label, data = rnorm(10), seed = seed)
}
method2 <- function(label, seed) {
tibble(method = 2, label = label, data = rnorm(10), seed = seed)
}
summarize_analysis = function(x) {
tibble(
method = x$method[1],
label = x$label[1],
seed = x$seed[1],
stat = c("mean", "sd"),
value = c(mean(x$data), sd(x$data))
)
}
targets <- tar_map(
values = tibble(method_function = rlang::syms(c("method1", "method2"))),
tar_target(
analysis,
method_function("NIH", seed = random_seed),
pattern = map(random_seed)
),
tar_target(
summary,
summarize_analysis(analysis),
pattern = map(analysis)
)
)
list(
tar_target(random_seed, seq_len(10)),
targets,
tar_target(slices, summary_method2, pattern = slice(summary_method2, index = c(3, 4)))
)
})
tar_make(reporter = "silent")
tar_read(slices)
#> # A tibble: 4 x 5
#> method label seed stat value
#> <dbl> <chr> <int> <chr> <dbl>
#> 1 2 NIH 3 mean 0.518
#> 2 2 NIH 3 sd 1.22
#> 3 2 NIH 4 mean -0.299
#> 4 2 NIH 4 sd 1.02
tar_read(slices, branches = 1)
#> # A tibble: 2 x 5
#> method label seed stat value
#> <dbl> <chr> <int> <chr> <dbl>
#> 1 2 NIH 3 mean 0.518
#> 2 2 NIH 3 sd 1.22 Created on 2021-04-16 by the reprex package (v2.0.0) |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In a paper I am writing, I use
targets
to perform an extensive sensitivity analysis, and I use both static and dynamic branching to fit models across varying specifications. For the most part, I usetar_combine()
and friends to aggregate across these varying specifications and produce some aggregation results about sensitivity.However, one of the models that I fit is the model I would actually like to report (i.e. everything else is a sensitivity analysis for that model). I want to do some specific followup work on that model (i.e. nicer plots, more publication ready diagnostics, etc, etc). I believe my problem is equivalent to selecting the target
summary_method2
corresponding to a particular random seed generated by the following (example ripped from https://books.ropensci.org/targets/static.html#dynamic-within-static-branching).Say I want to apply another function
polish_summary()
tosummary_method2 {random seed i care about}
alone. How would I do that?Beta Was this translation helpful? Give feedback.
All reactions