-
I want to run analyses of a dataset with a variety of parameters (variable definitions, grouping variables etc.) and then plot a subset of those analyses. I can put the parameters combinations into a tibble/target and then map over those to run the analyses. But how do I filter a subset of the dynamic analysis targets based on their parameter values? I could not find an example of this filtering step in the manual, so I came up with the following solution. (I simplified "plot" to just mean "print"). The solution is a bit unsatisfying to me, because it requires an extra target just for filtering, which possibly takes up extra storage, and because of the requirement to use Is there a cleaner way to achieve my goal? library(targets)
library(tidyverse)
library(tarchetypes)
tar_option_set(packages = "tidyverse")
list(
tar_target(parameters, seq_len(6)),
tar_target(analysis, tibble(parameter = parameters, output = parameters + 1), pattern = map(parameters)),
tar_target(analysis_subset, dplyr::filter(analysis, parameter %% 2 == 1)),
tar_target(plot, with(analysis_subset, print(output)), pattern = map(analysis_subset))
) My question is closely related to ropensci/drake#1342 (comment); @wlandau writes there that switching to targets solves the storage issue. How do I achieve this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 9 replies
-
I think your workaround is great. You might also have a look at composable patterns, e.g. #212 and https://books.ropensci.org/targets/dynamic.html#pattern-construction. You might have to make deep copies of some of your branches, but if |
Beta Was this translation helpful? Give feedback.
I think your workaround is great. You might also have a look at composable patterns, e.g. #212 and https://books.ropensci.org/targets/dynamic.html#pattern-construction. You might have to make deep copies of some of your branches, but if
analysis_subset
is small, then it might not be such a storage burden. Another option is dynamic-within-static branching, where you could statically branch over the parameter you want to filter on, dynamically branch over everything else, and just plot a single static branch.