R语言 不知道为什么visible=FALSE,不删除报表中的变量

zphenhs4  于 2023-09-27  发布在  其他
关注(0)|答案(1)|浏览(82)

下面是我使用的代码

library(Tplyr)
library(reporter)
library(tidyCDISC)

data(list=c('adsl','adae'), package='tidyCDISC')

adsl <- adsl %>% filter(SAFFL=='Y') %>% select(USUBJID, TRTA=TRT01A, TRTAN=TRT01AN) #%>% 
  # group_by(TRTA, TRTAN) %>% summarise(n=n())

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(ord_layer_index, label = "Variable", label_row = TRUE,
         # format = c("1" = "Cylinders",
                    # "2" = "Miles Per Gallon"), 
         # dedupe = TRUE, blank_after = TRUE) %>% 
  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)

在定义中,如果我们使用visible=FALSE,那么该变量应该删除,但它没有

我不想显示突出显示的列

kknvjkwl

kknvjkwl1#

所以,我认为问题是拼写/语法。我不能使用你的原始数据来测试我的理论,但是在创建tbl时,一个define语句(define(row_label1, visible = FALSE))使用了row_label1,但是在表本身中,名称是row label1。我想你需要用某种标识符:or ' ' to name the column within the table creation to apply thevisible=FALSE

相关问题