Skip to content

Using rbind to combine two tables when add_combo_levels is needed #340

@yutong1307

Description

@yutong1307

Hello,

I am trying to use rbind to combine two tables generated seperately. The following example works when there are only treatment columns in the tables I want to combine:

library(rtables)

l1 <- basic_table() %>%
  split_cols_by("ARM") %>%
  add_colcounts() %>%
  analyze("AGE")

tab1 <- build_table(l1, DM)

l2 <- basic_table() %>%
  split_cols_by("ARM") %>%
  add_colcounts() %>%
  analyze("SEX")

tab2 <- build_table(l2, DM)
rbind(tab1, tab2)

However, when I tried to include columns with combined count from two different treatment arms using add_combo_levels, I would received an error "Error in FUN(X[[i]], ...) : attempted to add child with non-matching, non-empty column info to an existing table"

library(rtables)
library(tibble)

combodf <- tribble(
  ~valname, ~label, ~levelcombo, ~exargs,
  "A_B", "Arms A+B", c("A: Drug X", "B: Placebo"), list(),
  "A_C", "Arms A+C", c("A: Drug X", "C: Combination"), list())

l1 <- basic_table() %>%
  split_cols_by("ARM", split_fun = add_combo_levels(combodf)) %>%
  add_colcounts() %>%
  analyze("AGE")

tab1 <- build_table(l1, DM)

l2 <- basic_table() %>%
  split_cols_by("ARM", split_fun = add_combo_levels(combodf)) %>%
  add_colcounts() %>%
  analyze("SEX")

tab2 <- build_table(l2, DM)
rbind(tab1, tab2)

Is there anyway to solve this problem?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions