摘要将是公式列表的列表,也就是说,最高级别的对象是一个列表,每个元素都是一个列表。这些低级列表的元素都是公式。提供的摘要:
summary_test <- list("Gender" =
list("Female" = ~ qwraps2::n_perc0(.mydata$sex == "F"),
"Male" = ~ qwraps2::n_perc0(.mydata$sex == "M")),
"Age" =
list("Mean" = ~ qwraps2::mean_sd(.mydata$age, denote_sd = "paren")),
"Comorbidities" =
list("HIV Positive" == ~ qwraps2::n_perc0(.mydata$hiv == 1),
"Type 2 Diabetes" == ~ qwraps2::n_perc0(.mydata$diabetes == 1)))
有==
“合并症”的定义,因此有逻辑陈述,而不是公式。
str(summary_test)
#> List of 3
#> $ Gender :List of 2
#> ..$ Female:Class 'formula' language ~qwraps2::n_perc0(.mydata$sex == "F")
#> .. .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
#> ..$ Male :Class 'formula' language ~qwraps2::n_perc0(.mydata$sex == "M")
#> .. .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
#> $ Age :List of 1
#> ..$ Mean:Class 'formula' language ~qwraps2::mean_sd(.mydata$age, denote_sd = "paren")
#> .. .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
#> $ Comorbidities:List of 2
#> ..$ : logi FALSE
#> ..$ : logi FALSE
此外,.mydata
需要用正确的 tidyverse data pronoun 替换.data
。正确的语法是:
summary_test <- list("Gender" =
list("Female" = ~ qwraps2::n_perc0(.data$sex == "F"),
"Male" = ~ qwraps2::n_perc0(.data$sex == "M")),
"Age" =
list("Mean" = ~ qwraps2::mean_sd(.data$age, denote_sd = "paren")),
"Comorbidities" =
list("HIV Positive" = ~ qwraps2::n_perc0(.data$hiv == 1),
"Type 2 Diabetes" = ~ qwraps2::n_perc0(.data$diabetes == 1)))
str(summary_test)
#> List of 3
#> $ Gender :List of 2
#> ..$ Female:Class 'formula' language ~qwraps2::n_perc0(.data$sex == "F")
#> .. .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
#> ..$ Male :Class 'formula' language ~qwraps2::n_perc0(.data$sex == "M")
#> .. .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
#> $ Age :List of 1
#> ..$ Mean:Class 'formula' language ~qwraps2::mean_sd(.data$age, denote_sd = "paren")
#> .. .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
#> $ Comorbidities:List of 2
#> ..$ HIV Positive :Class 'formula' language ~qwraps2::n_perc0(.data$hiv == 1)
#> .. .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
#> ..$ Type 2 Diabetes:Class 'formula' language ~qwraps2::n_perc0(.data$diabetes == 1)
#> .. .. ..- attr(*, ".Environment")=<environment: R_GlobalEnv>
由reprex 包(v0.3.0)于 2019 年 11 月 14 日创建
更新
从 qwraps2 v0.5.0 开始,.data
不再需要使用代词。