-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
09_tbl_too_long.qmd
129 lines (103 loc) · 3.78 KB
/
09_tbl_too_long.qmd
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
---
title: "Table Too Long"
format: html
editor: visual
---
## Testing output when the table is too long
```{r eval=FALSE}
library(gtsummary)
library(dplyr)
set.seed(123)
data <- dplyr::tibble(
id = 1:100,
age = sample(18:90, 100, replace = TRUE),
sex = sample(c("Male", "Female"), 100, replace = TRUE),
race = sample(c("White", "Black", "Asian", "Hispanic"), 100, replace = TRUE),
bmi = round(runif(100, 18, 35), 1),
smoking_status = sample(c("Never", "Former", "Current"), 100, replace = TRUE),
diabetes = sample(c("Yes", "No"), 100, replace = TRUE),
hypertension = sample(c("Yes", "No"), 100, replace = TRUE),
heart_disease = sample(c("Yes", "No"), 100, replace = TRUE),
cancer = sample(c("Yes", "No"), 100, replace = TRUE),
cholesterol = sample(c("Normal", "High"), 100, replace = TRUE),
exercise_frequency = sample(0:7, 100, replace = TRUE),
alcohol_intake = sample(c("None", "Low", "Moderate", "High"), 100, replace = TRUE),
family_history = sample(c("Yes", "No"), 100, replace = TRUE),
education = sample(c("High School", "College", "Graduate"), 100, replace = TRUE),
marital_status = sample(c("Single", "Married", "Divorced"), 100, replace = TRUE),
employment_status = sample(c("Employed", "Unemployed", "Retired"), 100, replace = TRUE),
region = sample(c("North", "South", "East", "West"), 100, replace = TRUE),
health_insurance = sample(c("Yes", "No"), 100, replace = TRUE),
medication = sample(c("Yes", "No"), 100, replace = TRUE),
visits_last_year = sample(0:10, 100, replace = TRUE),
satisfaction = sample(1:5, 100, replace = TRUE)
)
# Create summary table
summary_table <- data %>%
tbl_summary(
by = sex, # Group by sex
statistic = list(all_continuous() ~ "{mean} ({sd})", all_categorical() ~ "{n} ({p}%)"),
label = list(
age ~ "Age (years)",
bmi ~ "BMI",
smoking_status ~ "Smoking Status",
diabetes ~ "Diabetes",
hypertension ~ "Hypertension",
heart_disease ~ "Heart Disease",
cancer ~ "Cancer",
cholesterol ~ "Cholesterol",
exercise_frequency ~ "Exercise Frequency (days/week)",
alcohol_intake ~ "Alcohol Intake",
family_history ~ "Family History",
education ~ "Education Level",
marital_status ~ "Marital Status",
employment_status ~ "Employment Status",
region ~ "Region",
health_insurance ~ "Health Insurance",
medication ~ "On Medication",
visits_last_year ~ "Visits Last Year",
satisfaction ~ "Health Satisfaction (1-5)"
)
) %>%
add_n() %>%
modify_header(label = "**Characteristic**", estimate = "**Mean (SD) or N (%)**") %>%
modify_table_styling(columns = everything())
```
### gt_save PDF
```{r eval = FALSE}
gt::gtsave(as_gt(summary_table), filename = "outputs/pdf/too_long_gt_pdf.pdf")
```
[Preview the Output](outputs/pdf/too_long_gt_pdf.pdf)
- printed on multiple pages
- header and footnotes repeated on each page
### rmarkdown rendered PDF
```{r eval = FALSE}
gt_table
```
[Preview the Output](outputs/pdf/too_long_rmd_pdf.pdf)
- printed on one page
- table cut off at the end of the page
### gt_save rendered word file
```{r eval = FALSE}
gt::gtsave(as_gt(summary_table), filename = "outputs/docx/too_long_gt_word.docx")
```
[Preview the Output](outputs/docx/too_long_gt_word.docx)
- printed on multiple pages (continued)
- header repeated on each page
- footer only on the last page
### quarto rendered word file
```{r eval = FALSE}
gt_table
```
[Preview the Output](outputs/docx/too_long_qmd_word.docx)
- printed on multiple pages (continued)
- header repeated on each page
- footer only on the last page
### rmarkdown rendered word file
```{r eval = FALSE}
gt_table
```
[Preview the Output](outputs/docx/too_long_rmd_word.docx)
- printed on multiple pages (continued)
- header repeated on each page
- footer only on the last page