-
Notifications
You must be signed in to change notification settings - Fork 0
/
_targets.R
78 lines (75 loc) · 1.85 KB
/
_targets.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
library(targets)
tar_option_set(
packages = c("dplyr", "flextable", "ggplot2", "here", "purrr", "readr", "tibble", "tidyr", "wallis"),
format = "rds",
memory = "transient",
garbage_collection = TRUE
)
tar_source()
list(
tar_target(name = orders, command = seq(2, 80, 2)),
tar_target(
name = results,
command = {
tibble(
n = as.integer(orders),
greedy1 = list(greedy1(orders)),
greedy2 = list(greedy2(orders))
) |>
pivot_longer(-n) |>
mutate(
volume = map_dbl(value, "volume"),
n_filled = map_dbl(value, "n_filled"),
cells = map(value, "cells")
) |>
select(-value)
},
pattern = map(orders)
),
tar_target(
name = final_results,
command = {
results |>
select(-cells) |>
pivot_wider(names_from = name, values_from = c(volume, n_filled)) |>
rename(
t1 = n_filled_greedy1,
t2 = n_filled_greedy2,
r1 = volume_greedy1,
r2 = volume_greedy2
) |>
select(n, t1, t2, r1, r2)
}
),
tar_target(
name = plot_results,
command = {
ggplot(results, aes(n, volume, colour = name)) +
geom_line() +
theme_bw() +
theme(
legend.position = "bottom",
legend.title = element_blank()
)
}
),
tar_target(
name = final_results_as_flextable,
command = {
set_flextable_defaults(
font.size = 6,
padding = 6,
theme_fun = theme_zebra
)
flextable(final_results)
}
),
tar_target(
name = save_plot_results,
command = ggsave(plot = plot_results, filename = "png/plot-results.png", height = 1000, width = 1200, units = "px")
),
tar_target(
name = save_as_png,
command = save_as_image(final_results_as_flextable, path = "png/final-results.png")
)
)