-
Notifications
You must be signed in to change notification settings - Fork 0
/
_targets_ds_4.R
48 lines (39 loc) · 1.74 KB
/
_targets_ds_4.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
library(targets)
library(tarchetypes) # for tar_map()
# load the tidyverse quietly for each target
tar_option_set(packages = "tidyverse")
message("Static nested")
# a folder for the subfolders and
values <- tibble::tibble(
folders = c("data/lines", "data/circles", "data/others"),
names = fs::path_file(folders) # -> c("lines", "circles", "others")
)
# tar_map() generates R expressions, and substitute the desired 'values'
mapped <- tar_map(
values = values,
names = "names", # to avoid targets reporting "files_data.lines"
# special pair of targets
# readr is in charge of the aggregation (bind_rows())
tar_file_read(files, fs::dir_ls(folders, glob = "*tsv"), read_tsv(file = !!.x, show_col_types = FALSE)),
# nested tar_map
tar_map(
values = list(funs = c("mean", "sd")),
tar_target(summary, summarise(files, x_sum = funs(x), y_sum = funs(y)))
)
)
mcombined <- tar_combine(mean_combine,
# tarchetypes helper to select all averages
tar_select_targets(mapped, contains("_mean_")),
# .x placeholder all matching targets
# !!! unquote-splice operator
command = bind_rows(!!!.x, .id = "set"))
scombined <- tar_combine(sd_combine,
# tarchetypes helper to select all averages
tar_select_targets(mapped, contains("_sd_")),
# .x placeholder all matching targets
# !!! unquote-splice operator
command = bind_rows(!!!.x, .id = "set"))
combi <- tar_combine(stats, mcombined, scombined)
list(mapped, mcombined, scombined, combi)
# Sys.setenv(TAR_PROJECT = "ds_nested_static")
# targets::tar_make()