dir.create(temp_lib_loc)# install the old version of gtsummary into the temp libpak::pak("broom.helpers@1.15.0", lib = temp_lib_loc)pak::pak("gtsummary@1.7.2", lib = temp_lib_loc)trial2 <- trial %>%mutate(age2 = age)var_label(trial2$age) <-"Age 2"var_label(trial2$age2) <-"Age"
ex1 - from help doc
t1 <-glm(response ~ trt + grade + age, trial, family = binomial) %>%tbl_regression(exponentiate =TRUE)t2 <-coxph(Surv(ttdeath, death) ~ trt + grade + age, trial) %>%tbl_regression(exponentiate =TRUE)tbl_merge(tbls =list(t1, t2),tab_spanner =c("**Tumor Response**", "**Time to Death**")) |>modify_caption("NEW MERGE")
NEW MERGE
Characteristic
Tumor Response
Time to Death
OR
95% CI
p-value
HR
95% CI
p-value
Chemotherapy Treatment
Drug A
—
—
—
—
Drug B
1.13
0.60, 2.13
0.7
1.30
0.88, 1.92
0.2
Grade
I
—
—
—
—
II
0.85
0.39, 1.85
0.7
1.21
0.73, 1.99
0.5
III
1.01
0.47, 2.15
>0.9
1.79
1.12, 2.86
0.014
Age
1.02
1.00, 1.04
0.10
1.01
0.99, 1.02
0.3
Abbreviations: CI = Confidence Interval, HR = Hazard Ratio, OR = Odds Ratio
Abbreviations: CI = Confidence Interval, HR = Hazard Ratio, OR = Odds Ratio
ex2 change label and keep variable name the same
t3 <-coxph(Surv(ttdeath, death) ~ trt + grade + age, trial2) %>%tbl_regression(exponentiate =TRUE)# two rows for age heretbl_merge(tbls =list(t1, t3),tab_spanner =c("**Tumor Response**", "**Time to Death**")) |>modify_caption("NEW MERGE")
NEW MERGE
Characteristic
Tumor Response
Time to Death
OR
95% CI
p-value
HR
95% CI
p-value
Chemotherapy Treatment
Drug A
—
—
—
—
Drug B
1.13
0.60, 2.13
0.7
1.30
0.88, 1.92
0.2
Grade
I
—
—
—
—
II
0.85
0.39, 1.85
0.7
1.21
0.73, 1.99
0.5
III
1.01
0.47, 2.15
>0.9
1.79
1.12, 2.86
0.014
Age
1.02
1.00, 1.04
0.10
Age 2
1.01
0.99, 1.02
0.3
Abbreviations: CI = Confidence Interval, HR = Hazard Ratio, OR = Odds Ratio
Abbreviations: CI = Confidence Interval, HR = Hazard Ratio, OR = Odds Ratio
two rows for age here as well as the second characteristic column is kept and the merge duplicates rows for each variable. Error message does say this will happen.
The merging columns ("variable", "row_type", and "var_label") do not uniquely
identify rows for each table in `tbls`, and the merge may fail or result in a
malformed table.
ℹ If you previously called `tbl_stack()` on your tables, then merging with
`tbl_merge()` before calling `tbl_stack` may resolve the issue.
NEW MERGE
Tumor Response
Time to Death
Characteristic
OR
95% CI
p-value
Characteristic
HR
95% CI
p-value
Chemotherapy Treatment
Chemotherapy Treatment
Drug A
—
—
Drug A
—
—
Drug A
—
—
Drug B
1.30
0.88, 1.92
0.2
Drug B
1.13
0.60, 2.13
0.7
Drug A
—
—
Drug B
1.13
0.60, 2.13
0.7
Drug B
1.30
0.88, 1.92
0.2
Grade
Grade
I
—
—
I
—
—
I
—
—
II
1.21
0.73, 1.99
0.5
I
—
—
III
1.79
1.12, 2.86
0.014
II
0.85
0.39, 1.85
0.7
I
—
—
II
0.85
0.39, 1.85
0.7
II
1.21
0.73, 1.99
0.5
II
0.85
0.39, 1.85
0.7
III
1.79
1.12, 2.86
0.014
III
1.01
0.47, 2.15
>0.9
I
—
—
III
1.01
0.47, 2.15
>0.9
II
1.21
0.73, 1.99
0.5
III
1.01
0.47, 2.15
>0.9
III
1.79
1.12, 2.86
0.014
Age
1.02
1.00, 1.04
0.10
Age 2
1.01
0.99, 1.02
0.3
Abbreviations: CI = Confidence Interval, HR = Hazard Ratio, OR = Odds Ratio
The merging columns ("variable", "row_type", and "var_label") do not uniquely
identify rows for each table in `tbls`, and the merge may fail or result in a
malformed table.
ℹ If you previously called `tbl_stack()` on your tables, then merging with
`tbl_merge()` before calling `tbl_stack` may resolve the issue.
OLD MERGE
Tumor Response
Time to Death
Characteristic
OR
95% CI
p-value
Characteristic
HR
95% CI
p-value
Chemotherapy Treatment
Chemotherapy Treatment
Drug A
—
—
Drug A
—
—
Drug A
—
—
Drug B
1.30
0.88, 1.92
0.2
Drug B
1.13
0.60, 2.13
0.7
Drug A
—
—
Drug B
1.13
0.60, 2.13
0.7
Drug B
1.30
0.88, 1.92
0.2
Grade
Grade
I
—
—
I
—
—
I
—
—
II
1.21
0.73, 1.99
0.5
I
—
—
III
1.79
1.12, 2.86
0.014
II
0.85
0.39, 1.85
0.7
I
—
—
II
0.85
0.39, 1.85
0.7
II
1.21
0.73, 1.99
0.5
II
0.85
0.39, 1.85
0.7
III
1.79
1.12, 2.86
0.014
III
1.01
0.47, 2.15
>0.9
I
—
—
III
1.01
0.47, 2.15
>0.9
II
1.21
0.73, 1.99
0.5
III
1.01
0.47, 2.15
>0.9
III
1.79
1.12, 2.86
0.014
Age
1.02
1.00, 1.04
0.10
Age 2
1.01
0.99, 1.02
0.3
Abbreviations: CI = Confidence Interval, HR = Hazard Ratio, OR = Odds Ratio
One row for age here, the second characteristic column is kept and the merge duplicates rows for each variable. Error message does say this will happen.
The merging columns ("variable" and "row_type") do not uniquely identify rows
for each table in `tbls`, and the merge may fail or result in a malformed
table.
ℹ If you previously called `tbl_stack()` on your tables, then merging with
`tbl_merge()` before calling `tbl_stack` may resolve the issue.
NEW MERGE
Tumor Response
Time to Death
Characteristic
OR
95% CI
p-value
Characteristic
HR
95% CI
p-value
Chemotherapy Treatment
Chemotherapy Treatment
Drug A
—
—
Drug A
—
—
Drug A
—
—
Drug B
1.30
0.88, 1.92
0.2
Drug B
1.13
0.60, 2.13
0.7
Drug A
—
—
Drug B
1.13
0.60, 2.13
0.7
Drug B
1.30
0.88, 1.92
0.2
Grade
Grade
I
—
—
I
—
—
I
—
—
II
1.21
0.73, 1.99
0.5
I
—
—
III
1.79
1.12, 2.86
0.014
II
0.85
0.39, 1.85
0.7
I
—
—
II
0.85
0.39, 1.85
0.7
II
1.21
0.73, 1.99
0.5
II
0.85
0.39, 1.85
0.7
III
1.79
1.12, 2.86
0.014
III
1.01
0.47, 2.15
>0.9
I
—
—
III
1.01
0.47, 2.15
>0.9
II
1.21
0.73, 1.99
0.5
III
1.01
0.47, 2.15
>0.9
III
1.79
1.12, 2.86
0.014
Age
1.02
1.00, 1.04
0.10
Age 2
1.01
0.99, 1.02
0.3
Abbreviations: CI = Confidence Interval, HR = Hazard Ratio, OR = Odds Ratio
The merging columns ("variable" and "row_type") do not uniquely identify rows
for each table in `tbls`, and the merge may fail or result in a malformed
table.
ℹ If you previously called `tbl_stack()` on your tables, then merging with
`tbl_merge()` before calling `tbl_stack` may resolve the issue.
OLD MERGE
Tumor Response
Time to Death
Characteristic
OR
95% CI
p-value
Characteristic
HR
95% CI
p-value
Chemotherapy Treatment
Chemotherapy Treatment
Drug A
—
—
Drug A
—
—
Drug A
—
—
Drug B
1.30
0.88, 1.92
0.2
Drug B
1.13
0.60, 2.13
0.7
Drug A
—
—
Drug B
1.13
0.60, 2.13
0.7
Drug B
1.30
0.88, 1.92
0.2
Grade
Grade
I
—
—
I
—
—
I
—
—
II
1.21
0.73, 1.99
0.5
I
—
—
III
1.79
1.12, 2.86
0.014
II
0.85
0.39, 1.85
0.7
I
—
—
II
0.85
0.39, 1.85
0.7
II
1.21
0.73, 1.99
0.5
II
0.85
0.39, 1.85
0.7
III
1.79
1.12, 2.86
0.014
III
1.01
0.47, 2.15
>0.9
I
—
—
III
1.01
0.47, 2.15
>0.9
II
1.21
0.73, 1.99
0.5
III
1.01
0.47, 2.15
>0.9
III
1.79
1.12, 2.86
0.014
Age
1.02
1.00, 1.04
0.10
Age 2
1.01
0.99, 1.02
0.3
Abbreviations: CI = Confidence Interval, HR = Hazard Ratio, OR = Odds Ratio
ex3 change variable name and keep label the same
table does not merge properly because of mismatch between labels and variables but no error is thrown
Abbreviations: CI = Confidence Interval, HR = Hazard Ratio, OR = Odds Ratio
ex4 stack and merge
t1s <-tbl_stack(list(tbl_summary(trial, by = trt, include = age),tbl_summary(trial, by = trt, include = grade)))t2s <-tbl_stack(list(tbl_summary(trial, by = trt, include = age),tbl_summary(trial, by = trt, include = grade)))tbl_merge(list(t1s, t2s),merge_vars =c("row_type", "label")) |>modify_caption("NEW MERGE")
t3s <-tbl_stack(list(tbl_summary(trial2, by = trt, include = age),tbl_summary(trial2, by = trt, include = grade)))#same results at ex2 abovetbl_merge(list(t1s, t3s),merge_vars =c("variable", "row_type")) |>modify_caption("NEW MERGE")
The merging columns ("variable" and "row_type") do not uniquely identify rows
for each table in `tbls`, and the merge may fail or result in a malformed
table.
ℹ If you previously called `tbl_stack()` on your tables, then merging with
`tbl_merge()` before calling `tbl_stack` may resolve the issue.
The merging columns ("variable" and "row_type") do not uniquely identify rows
for each table in `tbls`, and the merge may fail or result in a malformed
table.
ℹ If you previously called `tbl_stack()` on your tables, then merging with
`tbl_merge()` before calling `tbl_stack` may resolve the issue.
The merging columns ("variable", "row_type", and "var_label") do not uniquely
identify rows for each table in `tbls`, and the merge may fail or result in a
malformed table.
ℹ If you previously called `tbl_stack()` on your tables, then merging with
`tbl_merge()` before calling `tbl_stack` may resolve the issue.
The merging columns ("variable", "row_type", and "var_label") do not uniquely
identify rows for each table in `tbls`, and the merge may fail or result in a
malformed table.
ℹ If you previously called `tbl_stack()` on your tables, then merging with
`tbl_merge()` before calling `tbl_stack` may resolve the issue.
OLD MERGE
Table 1
Table 2
Characteristic
Drug A N = 981
Drug B N = 1021
Characteristic
Drug A N = 981
Drug B N = 1021
Age
46 (37, 60)
48 (39, 56)
Unknown
7
4
Grade
Grade
I
35 (36%)
33 (32%)
I
35 (36%)
33 (32%)
I
35 (36%)
33 (32%)
II
32 (33%)
36 (35%)
I
35 (36%)
33 (32%)
III
31 (32%)
33 (32%)
II
32 (33%)
36 (35%)
I
35 (36%)
33 (32%)
II
32 (33%)
36 (35%)
II
32 (33%)
36 (35%)
II
32 (33%)
36 (35%)
III
31 (32%)
33 (32%)
III
31 (32%)
33 (32%)
I
35 (36%)
33 (32%)
III
31 (32%)
33 (32%)
II
32 (33%)
36 (35%)
III
31 (32%)
33 (32%)
III
31 (32%)
33 (32%)
Age 2
46 (37, 60)
48 (39, 56)
Unknown
7
4
1 Median (Q1, Q3)
ex 6 stack and merge, different variable same label
t4s <-tbl_stack(list(tbl_summary(trial2, by = trt, include = age2),tbl_summary(trial2, by = trt, include = grade)))# does merge, shows two age variablestbl_merge(tbls =list(t1s, t4s)) |>modify_caption("NEW MERGE")
ex8 change variable to charcater keep label the same
trial3 <- trial %>%mutate(grade =as.character(grade))var_label(trial3$grade) <-"Grade"t3sm <-tbl_stack(list(tbl_summary(trial3 %>%filter(grade %in%c("II","III")), by = trt, include = age),tbl_summary(trial3 %>%filter(grade %in%c("II","III")), by = trt, include = grade)))#merges as expected even when one was factor and other was charactertbl_merge(list(t1sm, t3sm)) |>modify_caption("NEW MERGE")
ex9 change label, stack and merge, different variable levels
var_label(trial3$grade) <-"Grade2"t5sm <-tbl_stack(list(tbl_summary(trial3 %>%filter(grade %in%c("II","III")), by = trt, include = age),tbl_summary(trial3 %>%filter(grade %in%c("II","III")), by = trt, include = grade)))# two grade variables appear as expectedtbl_merge(list(t1sm, t5sm)) |>modify_caption("NEW MERGE")