Skip to content

Commit be2b74f

Browse files
Update SAFE template table structure from flextable to asar as per #428
1 parent a6e60f2 commit be2b74f

File tree

2 files changed

+70
-77
lines changed

2 files changed

+70
-77
lines changed

inst/templates/safe/01c_plan-team.qmd

Lines changed: 64 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,33 @@
55
```{r}
66
#| eval: false
77
#| echo: false
8+
# install.packages("devtools")
9+
# devtools::install_github("BenWilliams-NOAA/safe")
10+
11+
year <- format(Sys.time(), "%Y")
12+
813
ptdata <- safe::ptdata
914
10-
flextable::font(
11-
flextable::footnote(flextable::flextable(ptdata),
12-
j = 3, part = "header", ref_symbols = "1",
13-
value = flextable::as_paragraph("Total biomass (age 4+) estimates from age-structured model.")
14-
),
15-
fontname = "Times New Roman",
16-
part = "all"
17-
) %>%
18-
flextable::footnote(
19-
i = 2, j = 7, part = "body", ref_symbols = "2",
20-
value = flextable::as_paragraph(
21-
flextable::as_chunk(paste0(paste0("Current as of ", date, " . Source: NMFS Alaska Regional Office Catch Accounting System
22-
via the AKFIN database (http://www.akfin.org).")))
23-
)
24-
) %>%
25-
flextable::set_formatter(Year = function(x) sprintf("%s", x)) %>%
26-
flextable::merge_at(i = 1:4, j = 1) %>%
27-
flextable::hrule(rule = "exact") %>%
28-
flextable::hline_top(part = "all") %>%
29-
flextable::hline_bottom() %>%
30-
flextable::fix_border_issues()
15+
ptdata |>
16+
gt::gt() |>
17+
gt::tab_footnote(
18+
footnote = "Total biomass (age 4+) estimates from age-structured model.",
19+
locations = gt::cells_column_labels(columns = Biomass)
20+
) |>
21+
gt::tab_footnote(
22+
footnote = paste0("Current as of ", year, ". Source: NMFS Alaska Regional Office Catch Accounting System
23+
via the AKFIN database (http://www.akfin.org)."),
24+
locations = cells_column_labels(columns = Catch)
25+
) |>
26+
gt::fmt_integer(columns = Year, sep_mark = "") |>
27+
gt::fmt_integer(columns = Biomass:Catch, sep_mark = ",") |>
28+
gt::tab_options(
29+
column_labels.font.weight = "bold",
30+
table_body.hlines.style = "none"
31+
) |>
32+
gt::sub_missing(
33+
missing_text = ""
34+
)
3135
```
3236

3337
{{< pagebreak >}}
@@ -37,51 +41,43 @@ via the AKFIN database (http://www.akfin.org).")))
3741
#| echo: false
3842
ptdata2 <- safe::ptdata2
3943
40-
flextable::font(
41-
flextable::footnote(flextable::flextable(ptdata2[-1, ]),
42-
j = 6, part = "header", ref_symbols = "2",
43-
value = flextable::as_paragraph(flextable::as_chunk(
44-
paste0(paste0(
45-
"Current as of ", date,
46-
" . Source: NMFS Alaska Regional Office Catch Accounting System
47-
via the AKFIN database (http://www.akfin.org)."
48-
))
49-
))
50-
),
51-
fontname = "Times New Roman",
52-
part = "all"
53-
) %>%
54-
flextable::add_header(values = ptdata2[1, ]) %>%
55-
flextable::border_remove() %>%
56-
flextable::merge_at(j = 1) %>%
57-
flextable::compose(
58-
i = 1, j = 3:6,
59-
value = flextable::as_paragraph(as.character(year - 1)),
60-
part = "header"
61-
) %>%
62-
flextable::compose(
63-
i = 1, j = 7:8,
64-
value = flextable::as_paragraph(as.character(year)),
65-
part = "header"
66-
) %>%
67-
flextable::compose(
68-
i = 1, j = 9:10,
69-
value = flextable::as_paragraph(as.character(year + 1)),
70-
part = "header"
71-
) %>%
72-
flextable::merge_at(i = 1, j = 3:6, part = "header") %>%
73-
flextable::merge_at(i = 1, j = 7:8, part = "header") %>%
74-
flextable::merge_at(i = 1, j = 9:10, part = "header") %>%
75-
flextable::align(i = 1, part = "header", align = "center") %>%
76-
flextable::compose(
77-
i = 2, j = 7:10,
78-
value = flextable::as_paragraph(rep(c("ABC", "OFL"), 2)),
79-
part = "header"
80-
) %>%
81-
flextable::hline_top(part = "body") %>%
82-
flextable::hline_top(part = "header") %>%
83-
flextable::vline(j = c(2, 6, 8)) %>%
84-
flextable::hline_bottom(part = "body") %>%
85-
flextable::fix_border_issues(part = "all") %>%
86-
flextable::set_table_properties(width = .5, layout = "autofit")
44+
year <- format(Sys.time(), "%Y")
45+
date <- Sys.Date()
46+
47+
yr_prev <- ptdata2[1, 3] # "2021"
48+
yr_curr <- ptdata2[1, 7] # "2022"
49+
yr_next <- ptdata2[1, 9] # "2023"
50+
51+
ptdata2[-1, ] |>
52+
gt::gt() |>
53+
gt::tab_options(
54+
column_labels.font.weight = "bold",
55+
table_body.hlines.style = "none"
56+
) |>
57+
gt::cols_label(
58+
OFL = paste(yr_prev, "OFL"),
59+
ABC = paste(yr_prev, "ABC"),
60+
TAC = paste(yr_prev, "TAC"),
61+
Catch = paste(yr_prev, "Catch"),
62+
OFL.1 = paste(yr_curr, "ABC"),
63+
ABC.1 = paste(yr_curr, "OFL"),
64+
OFL.2 = paste(yr_next, "ABC"),
65+
ABC.2 = paste(yr_next, "OFL")
66+
) |>
67+
gt::tab_footnote(
68+
footnote = paste0("Current as of ", date, ". Source: NMFS Alaska Regional Office Catch Accounting System via the AKFIN database (http://www.akfin.org)."),
69+
locations = cells_column_labels(columns = 6)
70+
) |>
71+
gt::fmt_integer() |>
72+
gt::cols_align(align = "center", columns = 3:10) |>
73+
gt::cols_align(align = "left", columns = 1:2) |>
74+
gt::sub_missing(
75+
missing_text = ""
76+
) |>
77+
gt::tab_style(
78+
style = cell_borders(sides = "right", color = "mediumgrey", weight = px(2)),
79+
locations = list(
80+
cells_body(columns = c(6, 8)),
81+
cells_column_labels(columns = c(6, 8))
82+
) )
8783
```

inst/templates/safe/05_data.qmd

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,12 @@ data.frame(
3232
"1991-1997, 2003, 2007, 2009, 2011, 2013, 2015, 2017, 2019"
3333
)
3434
) |>
35-
flextable::flextable() |>
36-
flextable::width(j = ~Source, width = 1) |>
37-
flextable::width(j = ~Data, width = 1.5) |>
38-
flextable::width(j = ~Years, width = 4) |>
39-
flextable::merge_v(j = 1) |>
40-
flextable::font(fontname = "Times", part = "all") |>
41-
flextable::fontsize(size = 10) |>
42-
flextable::theme_vanilla() |>
43-
flextable::fix_border_issues()
35+
gt::gt() |>
36+
gt::cols_width(
37+
Source ~ px(100),
38+
Data ~ px(150),
39+
Years ~ px(400)
40+
)
4441
```
4542

4643
## Fishery

0 commit comments

Comments
 (0)