Not sure why the visible=FALSE, does not drop the variables in the report
jagadishkatam opened this issue · comments
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_replace_all(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)
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)
![image](https://private-user-images.githubusercontent.com/83913148/269721768-71398fa4-ec23-4c58-a890-614197cbfa1a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA2MDk2OTQsIm5iZiI6MTcyMDYwOTM5NCwicGF0aCI6Ii84MzkxMzE0OC8yNjk3MjE3NjgtNzEzOThmYTQtZWMyMy00YzU4LWE4OTAtNjE0MTk3Y2JmYTFhLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzEwVDExMDMxNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQ0MDM4NDE0ZDdkNzJjODAzZWRhYjFjOGI3YjZhYTY5YWY5YjQ2MjcyZmQwNzU0MjljZmFhMjk4NmM2YzA0NjkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.1I_Th9gsWl85HXdHT5T5H4vDJkS5A1cvzgY7Y5aE58k)