question about `gtsummary::tbl_merge()` for `tbl_summary` and `tbl_svysummary`

library(tidyverse)
library(gtsummary)
library(survey) 
library(srvyr) 

penguins <- palmerpenguins::penguins %>% tidyr::drop_na()

t1 <- penguins %>% gtsummary::tbl_summary()

t2 <- penguins %>%
  mutate(
    Weight  = runif(333, 1, 10) * 592693,
    VarUnit = sample(1:3, size = 333, replace = TRUE), 
    Stratum = sample(1:5, size = 333, replace = TRUE)
  ) %>% 
  srvyr::as_survey_design(
    weights = Weight,
    strata  = Stratum,
    ids     = VarUnit,
    nest    = TRUE
  ) %>% 
  gtsummary::tbl_svysummary(
    include = c(everything(), -Weight, -VarUnit, -Stratum)
  )

tbl_merge(list(t2, t1)) # work

tbl_merge(list(t1, t2)) # does not work

I don't know why, can you give me some advice and help?
Thanks

Hi @perlatex
The column types in t1 and t2 are not identical. A numeric conversion is required on merging which is OK in one direction (integer --> double) but not in the other direction (double --> integer). It might be worth pointing out this 'glitch' with the package maintainer.

1 Like