[show-and-tell] A convenience function to collect targets and refer to them by groups #1196
Closed
noamross
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
The library(targets)
library(tarchetypes)
list(
abc = tar_plan(abc1 = TRUE, xyz1 = TRUE),
xyz = tar_plan(abc2 = TRUE, xyz2 = TRUE)
) Then βΆ dispatched target abc1
β completed target abc1 [0 seconds]
βΆ dispatched target abc2
β completed target abc2 [0 seconds]
βΆ completed pipeline [0.079 seconds] To interact with groups of targets in |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Help
Description
This is a convenience function we've been using. Place
all_targets()
at the end of a_targets.R
file and it will inspect the environment for any targets, as well as any lists that are made up of all targets (such as those created withtar_plan()
), collect them and output them as a list. This way you don't have to maintain alist()
call at the bottom of the file.We make use of
tar_plan()
a lot, both for the covenience of the=
syntax and also to collect targets into convenient groups, likeraw_data_targets <- tar_plan(...)
. We wanted a convenient way to build or inspect those group, so I also just addedadd_list_names = TRUE
to this. It looks for anytar_plan()
-type lists, and after collecting their contents, writes vectors of the target names to the environment. This way, if you haveraw_data_targets <- tar_plan(...)
in _targets.R, one can runtar_make(raw_data_targets)
,tar_visnetwork(TRUE, raw_data_targets)
or any other targets function that evaluates target names. It won't work with things liketar_load()
that don't source_targets.R
first.Running
tar_make(raw_data_targets)
right now does give a deprecation error:So the better way to do this is
tar_make(all_of(raw_data_targets))
Any thoughts on this? Is it dangerous in some way?
Beta Was this translation helpful? Give feedback.
All reactions