-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_targets.R
68 lines (66 loc) · 2.15 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
library(targets)
tar_option_set(
packages = c("dplyr", "ggplot2", "purrr", "tibble", "wallis")
)
list(
tar_target(
name = example_square,
command = {
n <- 10
r <- Room$new(size = n)
for(e in r$empty_cells) {
for(p in r$free_pairs) {
if(r$is_available(e, p)) {
r$set(e, p)
break()
}
}
}
r$cells <- r$cells |>
mutate(
n_avail = map_dbl(r$cells$avail, length)
)
return(r)
}
),
tar_target(
name = example_square_plot,
command = {
ggplot(data = example_square$cells, aes(col, row)) +
geom_text(data = example_square$cells |> filter(!is.na(first)), aes(label = paste(first, second, sep = ","))) +
geom_segment(data = wallis:::grid_lines(9, 9), aes(x = x, y = y, xend = xend, yend = yend), linewidth = .1) +
scale_y_reverse() +
coord_fixed() +
theme_void() +
theme(
legend.position = "none"
)
}
),
tar_target(
name = save_example_square_plot,
command = ggsave(plot = example_square_plot, filename = "plots/example-square-plot.png", bg = "white", width = 1000, height = 1000, units = "px"),
format = "file"
),
tar_target(
name = colour_example_plot,
command = {
ggplot(data = example_square$cells, aes(col, row)) +
geom_tile(data = example_square$cells |> filter(is.na(first)), aes(fill = as.factor(n_avail))) +
geom_text(data = example_square$cells |> filter(!is.na(first)), aes(label = paste(first, second, sep = ","))) +
geom_text(data = example_square$cells |> filter(is.na(first)) |> filter(n_avail > 0), aes(label = avail)) +
geom_segment(data = wallis:::grid_lines(9, 9), aes(x = x, y = y, xend = xend, yend = yend), linewidth = .1) +
scale_y_reverse() +
coord_fixed() +
theme_void() +
theme(
legend.position = "none"
)
}
),
tar_target(
name = save_colour_example_plot,
command = ggsave(plot = colour_example_plot, filename = "plots/colour-example-plot.png", bg = "white", width = 3000, height = 3000, units = "px"),
format = "file"
)
)