-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path5-functions.Rmd
91 lines (68 loc) · 2.25 KB
/
5-functions.Rmd
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
79
80
81
82
83
84
85
86
87
88
89
90
91
# Helpful Functions
## P-value Formatting
```{r}
pval_label_apa <- function(value,
breaks = c(.05, .01, .001),
symbols = c("*", "**", "***"),
decimals = 3,
leading = FALSE){
value_apa = MOTE::apa(value = value,
decimals = decimals,
leading = leading)
value_apa_min = MOTE::apa(value = breaks[3],
decimals = decimals,
leading = leading)
dplyr::case_when(value < breaks[3] ~ glue::glue("p < {value_apa_min} {symbols[3]}"),
value == breaks[3] ~ glue::glue("p = {value_apa_min} {symbols[3]}"),
value <= breaks[2] ~ glue::glue("p = {value_apa} {symbols[2]}"),
value <= breaks[1] ~ glue::glue("p = {value_apa} {symbols[1]}"),
value > breaks[1] ~ glue::glue("p = {value_apa}"))
}
```
```{r}
c(0.23, 0.023, 0.0023, 0.00023) %>% pval_label_apa()
```
```{r}
c(0.05, 0.01, 0.001) %>% pval_label_apa()
```
## APA Table Formatting
```{r}
gt_apa <- function(x, title = " ", ...) {
gt(x, ...) %>%
tab_options(
table.border.top.color = "white",
heading.title.font.size = px(16),
column_labels.border.top.width = 3,
column_labels.border.top.color = "black",
column_labels.border.bottom.width = 3,
column_labels.border.bottom.color = "black",
table_body.border.bottom.color = "black",
table.border.bottom.color = "white",
table.width = pct(100),
table.background.color = "white"
) %>%
cols_align(align="center") %>%
tab_style(
style = list(
cell_borders(
sides = c("top", "bottom"),
color = "white",
weight = px(1)
),
cell_text(
align="center"
),
cell_fill(color = "white", alpha = NULL)
),
locations = cells_body(
columns = everything(),
rows = everything()
)
) %>%
#title setup
tab_header(
title = html("<i>", title, "</i>")
) %>%
opt_align_table_header(align = "left")
}
```