Closed jagadishkatam closed 11 months ago
Hi @jagadishkatam,
It looks like this is a question on reporter and not Tplyr.
But looking at your code, the issue is using the show_cols
argument in the create_table()
function. It seems that this will override the visible=FALSE
parameters withing define()
.
Try this:
tbl <- create_table(dt) %>%
define(row_label1, visible = FALSE) %>%
define(row_label2, label = "", indent = .25) %>%
define(var1_Placebo, label = "Placebo", align = "center", n = 86) %>%
define(var1_Xanomeline_High_Dose, label = "Xanomeline High Dose", align = "center", n = 84) %>%
define(var1_Xanomeline_Low_Dose, label = "Xanomeline Low Dose", align = "center", n = 84) %>%
define(ord_layer_index, visible = FALSE) %>%
define(ord_layer_1, visible = FALSE) %>%
define(ord_layer_2, visible = FALSE)
Hi @mstackhouse, Appreciate your prompt response, it worked for me as per your suggestion.
However i am struck with another issue, the 'subjects with any adverse events' does not align with adverse event counts and percentage. I am not sure of the reason.
I am using the same code as given earlier except for below update
tbl <- create_table(dt) %>% define(row_label1, visible = FALSE) %>% define(row_label2, label = "", indent = .25) %>% define(var1_Placebo, label = "Placebo", align = "left", n = 86) %>% define(var1_Xanomeline_High_Dose, label = "Xanomeline High Dose", align = "left", n = 84) %>% define(var1_Xanomeline_Low_Dose, label = "Xanomeline Low Dose", align = "left", n = 84) %>% define(ord_layer_index, visible = FALSE) %>% define(ord_layer_1, visible = FALSE, blank_after = TRUE) %>% define(ord_layer_2, visible = FALSE)
library(Tplyr) library(reporter) library(tidyCDISC)
data(list=c('adsl','adae'), package='tidyCDISC')
adsl <- adsl %>% filter(SAFFL=='Y') %>% select(USUBJID, TRTA=TRT01A, TRTAN=TRT01AN)
adae <- adae %>% select(-c(TRTA, TRTAN)) %>% inner_join(adsl, by='USUBJID')
adae <- adae %>% select(USUBJID, TRTA, TRTAN, AEBODSYS, AEDECOD) %>% distinct() %>% mutate(all='Subjects with any Adverse Events', across(c(AEBODSYS, AEDECOD), ~ str_to_title(.)))
t <- Tplyr::tplyr_table(adae, TRTA) %>% set_pop_data(adsl) %>% set_pop_treat_var(TRTA) %>% set_pop_where(TRUE) %>% Tplyr::add_layer(group_count(all, by='Subjects with any Adverse Events')) %>% set_distinct_by(USUBJID) %>% Tplyr::add_layer(group_count(vars(AEBODSYS,AEDECOD))) %>% set_distinct_by(USUBJID)
dt <- t %>% Tplyr::build() #%>% View() dt <- dt %>% mutate(ord_layer_1=ifelse(row_number()!=1,ord_layer_1+1,ord_layer_1))
names(dt) <- str_replaceall(names(dt),'\s','')
tbl <- create_table(dt, show_cols = 1:8) %>%
define(row_label1, visible = FALSE) %>% define(row_label2, label = "", indent = .25) %>% define(var1_Placebo, label = "Placebo", align = "center", n = 86) %>% define(var1_Xanomeline_High_Dose, label = "Xanomeline High Dose", align = "center", n = 84) %>% define(var1_Xanomeline_Low_Dose, label = "Xanomeline Low Dose", align = "center", n = 84) %>% define(ord_layer_index, visible = FALSE) %>% define(ord_layer_1, visible = FALSE) %>% define(ord_layer_2, visible = FALSE)
pth <- file.path(tempdir(), "test1.rtf")
rpt <- create_report(pth, output_type = "RTF", orientation = "landscape") %>% titles("Table 1.0", "Adverse Events", "Population: Safety") %>% set_margins(top = 1, bottom = 1) %>% add_content(tbl)
write_report(rpt)