-
Notifications
You must be signed in to change notification settings - Fork 0
/
articleone-tables.R
67 lines (62 loc) · 2.72 KB
/
articleone-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
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
characteristics <- function(dset, type = "fr02") {
if (type == "fr02") {
factors <- c("HT", "HRX", "sex", "curr_smk", "curr_diab", "plate")
names <- list("Age, y (SD)" = "AGE",
"Female, N (%)" = "sex",
"BMI, kg/m² (SD)" = "BMI",
"Systolic blood pressure, mmHg (SD)" = "SBP",
"Diastolic blood pressure, mmHg (SD)" = "DBP",
"Pulse pressure, mmHg (SD)" = "PP",
"Mean arterial pressure, mmHg (SD)" = "MAP",
"Hypertension, N (%)" = "HT",
"Antihypertensive medication, N (%)" = "HRX",
"Current smoker, N (%)" = "curr_smk",
"Diabetes mellitus, N (%)" = "curr_diab")
} else {
factors <- c("HT8", "HRX8", "sex", "CURRSMK8", "curr_diab8", "plate")
names <- list("Age, y (SD)" = "AGE8",
"Female, N (%)" = "sex",
"BMI, kg/m² (SD)" = "BMI8",
"Systolic blood pressure, mmHg (SD)" = "SBP8",
"Diastolic blood pressure, mmHg (SD)" = "DBP8",
"Pulse pressure, mmHg (SD)" = "PP8",
"Mean arterial pressure, mmHg (SD)" = "MAP8",
"Hypertension, N (%)" = "HT8",
"Antihypertensive medication, N (%)" = "HRX8",
"Current smoker, N (%)" = "CURRSMK8",
"Diabetes mellitus, N (%)" = "curr_diab8")
}
tableobject <- tableone::CreateTableOne(data = dset, vars = unlist(names), factorVars = factors)
tablecsv <- print(tableobject,
exact = "stage",
quote = FALSE,
noSpaces = TRUE,
printToggle = FALSE,
digits = 1,
pDigits = 3,
contDigits=1)
title <- "Characteristics"
overall <- paste0("Cases, n=", dim(dset)[1])
tablecsv %>%
as.data.frame %>%
dplyr::filter(row_number() > 1) %>%
dplyr::mutate(!!title := names(names), !!overall := Overall) %>%
dplyr::select(-Overall)
}
typologyformatter <- function(data, font = 12, typology) {
flex <- flextable(data = data) %>%
flextable::theme_booktabs()
if (!missing(typology)) {
flex <- flex %>%
set_header_df(mapping = typology, key = "col_keys") %>%
merge_h(part = "header")
}
flex %>%
flextable::bold(bold = FALSE, part = "header") %>%
flextable::bold(bold = FALSE, part = "body") %>%
flextable::fontsize(size = font, part = "header") %>%
flextable::fontsize(size = font, part = "body") %>%
flextable::align(align = "center", part = "all") %>%
flextable::align(align = "left", part = "header", j = 1) %>%
flextable::align(align = "left", part = "body", j = 1)
}