-
Notifications
You must be signed in to change notification settings - Fork 0
/
bd_rr2_tables.R
42 lines (36 loc) · 1.91 KB
/
bd_rr2_tables.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
# possibly also use for aim 2 cum table and a variant for aim 1 table(s)
# obsolete?
bd_rr2_tables <- function(my_sheet, my_caption, bold_rows = 0) {
my_foot <- c(
"NA = Data not applicable, either model not run or weeks not included.",
paste("Model was adjusted for maternal education level, maternal smoking, ",
"tract-level median income, conception season, ",
"and the indicated green space "),
paste("variable. Week 0 is week of conception. ",
"Week 12 is the end of the first trimester of pregnancy.")
)
t <- readxl::read_xls("data/model2rr_tables.xls", sheet = my_sheet) |>
dplyr::filter(!is.na(bd)) |>
dplyr::mutate(greenlbl = ifelse(grepl("green", green),
"composite of grass, trees, and water within buffer",
"composite of grass and trees within buffer"),
pollutant = paste("Weekly", air, measure, "concentration,", greenlbl),
week = 12 - lag) |> dplyr::select(-lag) |>
dplyr::arrange(pollutant, week)
n <- c("Week", paste0(c(50, seq(100, 500, by = 100)), "m buffer"))
r <- table(t$pollutant)
t |> dplyr::select(week, b_50:b_500) |>
kable(booktabs = TRUE, format = "latex", longtable = T, escape = F, #
caption = my_caption, col.names = n, align = rep("c", 7)) |>
row_spec(bold_rows, bold=TRUE) |>
column_spec(1, bold = TRUE, width = "2.5em") |> #
column_spec(2:7, bold = FALSE, width = "8em") |> #
kableExtra::group_rows(index = r, escape = F) |> #
kableExtra::row_spec(cumsum(r), hline_after = TRUE) |>
# column_spec(5:6, bold = FALSE, width = "8em") |> #
kableExtra::kable_styling(
latex_options = c("repeat_header"), # "hold_position", "striped",
font_size = 10.5, # full_width = TRUE, position = "center",
repeat_header_continued = "\\textit{(Continued on Next Page...)}") |>
footnote(my_foot)
}