From f82ee16cd331ab631af9c02036d5fce074ec0f7c Mon Sep 17 00:00:00 2001 From: Andreas Gammelgaard Damsbo Date: Sun, 9 Nov 2025 12:04:29 +0100 Subject: [PATCH] fest: falg to se detail level of characteristics table --- CITATION.cff | 2 +- DESCRIPTION | 2 +- NEWS.md | 4 + R/app_version.R | 2 +- R/baseline_table.R | 35 ++++++- R/hosted_version.R | 2 +- R/sysdata.rda | Bin 2840 -> 2695 bytes R/ui_elements.R | 11 +++ SESSION.md | 20 +--- app_docker/app.R | 102 ++++++++++++++++++--- app_docker/translations/translation_da.csv | 4 + app_docker/translations/translation_de.csv | 4 + app_docker/translations/translation_sv.csv | 4 + app_docker/translations/translation_sw.csv | 4 + inst/translations/translation_da.csv | 4 + inst/translations/translation_de.csv | 4 + inst/translations/translation_sv.csv | 4 + inst/translations/translation_sw.csv | 4 + man/create_baseline.Rd | 12 ++- 19 files changed, 185 insertions(+), 39 deletions(-) diff --git a/CITATION.cff b/CITATION.cff index 265698dc..fcab7f68 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -8,7 +8,7 @@ message: 'To cite package "FreesearchR" in publications use:' type: software license: AGPL-3.0-or-later title: 'FreesearchR: Easy data analysis for clinicians' -version: 25.10.5 +version: 25.11.1 doi: 10.5281/zenodo.14527429 identifiers: - type: url diff --git a/DESCRIPTION b/DESCRIPTION index bb7e367e..27e92e13 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: FreesearchR Title: Easy data analysis for clinicians -Version: 25.10.5 +Version: 25.11.1 Authors@R: c( person("Andreas Gammelgaard", "Damsbo",email="agdamsbo@clin.au.dk", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-7559-1154")), diff --git a/NEWS.md b/NEWS.md index 1345a963..48596f4f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# FreesearchR 25.11.1 + +*NEW* Added option to select extensive baseline table selecting between "Minimal" (current) or "Extensive" which adds mean/sd and min/max as well as plots all levels also for dichotomous variables. + # FreesearchR 25.10.5 *NEW* New character/text split function available. A selection of delimiters are recognised and selectable. Function only available if splittable variables are present. diff --git a/R/app_version.R b/R/app_version.R index d67b66a1..042488b0 100644 --- a/R/app_version.R +++ b/R/app_version.R @@ -1 +1 @@ -app_version <- function()'25.10.5' +app_version <- function()'25.11.1' diff --git a/R/baseline_table.R b/R/baseline_table.R index ecab00b8..203197f6 100644 --- a/R/baseline_table.R +++ b/R/baseline_table.R @@ -12,7 +12,6 @@ #' mtcars |> baseline_table() #' mtcars |> baseline_table(fun.args = list(by = "gear")) baseline_table <- function(data, fun.args = NULL, fun = gtsummary::tbl_summary, vars = NULL) { - out <- do.call(fun, c(list(data = data), fun.args)) return(out) } @@ -23,19 +22,26 @@ baseline_table <- function(data, fun.args = NULL, fun = gtsummary::tbl_summary, #' #' @param data data #' @param ... passed as fun.arg to baseline_table() -#' @param strat.var grouping/strat variable #' @param add.p add comparison/p-value #' @param add.overall add overall column +#' @param by.var specify stratification variable +#' @param theme set table theme +#' @param detail_level specify detail level. Either "minimal" or "extended". #' #' @returns gtsummary table list object #' @export #' #' @examples #' mtcars |> create_baseline(by.var = "gear", add.p = "yes" == "yes") +#' mtcars |> create_baseline(by.var = "gear", detail_level = "extended") +#' mtcars |> create_baseline(by.var = "gear", detail_level = "extended",type = list(gtsummary::all_dichotomous() ~ "categorical"),theme="nejm") +#' #' create_baseline(default_parsing(mtcars), by.var = "am", add.p = FALSE, add.overall = FALSE, theme = "lancet") -create_baseline <- function(data, ..., by.var, add.p = FALSE, add.overall = FALSE, theme = c("jama", "lancet", "nejm", "qjecon")) { +create_baseline <- function(data, ..., by.var, add.p = FALSE, add.overall = FALSE, theme = c("jama", "lancet", "nejm", "qjecon"), detail_level = c("minimal", "extended")) { theme <- match.arg(theme) + detail_level <- match.arg(detail_level) + if (by.var == "none" | !by.var %in% names(data)) { by.var <- NULL } @@ -53,11 +59,32 @@ create_baseline <- function(data, ..., by.var, add.p = FALSE, add.overall = FALS args <- list(...) + # browser() + + if (!any(hasName(args, c("type", "statistic")))) { + if (detail_level == "extended") { + args <- + modifyList( + args, + list( + type = list(gtsummary::all_continuous() ~ "continuous2", + gtsummary::all_dichotomous() ~ "categorical"), + statistic = list(gtsummary::all_continuous() ~ c( + "{median} ({p25}, {p75})", + "{mean} ({sd})", + "{min}, {max}")) + ) + ) + } + } + parameters <- list( data = data, - fun.args = list(by = by.var, ...) + fun.args = purrr::list_flatten(list(by = by.var, args)) ) + + # browser() out <- do.call( baseline_table, parameters diff --git a/R/hosted_version.R b/R/hosted_version.R index 125f33e1..d1519d07 100644 --- a/R/hosted_version.R +++ b/R/hosted_version.R @@ -1 +1 @@ -hosted_version <- function()'v25.10.5-251031' +hosted_version <- function()'v25.11.1-251109' diff --git a/R/sysdata.rda b/R/sysdata.rda index d6694eef104dd8c498804324a18967f6806622ef..d644c1986565e8c198017c66c6b9511a2ec9b3da 100644 GIT binary patch literal 2695 zcmV;23V8KGT4*^jL0KkKS?Q_n-2fRo|HS|QXazw3|KNXb-@w2B|L{Nn06+)<;0zxZ zA=um=9Y6}%K#-umd*o0G`UaF-H8BA+045_wr1WHrBxa39CXE09(8;E02BruJp;O3W zN190eP|z{}000dQGypKu5G5*T14e0^+Z zg&2UyW1%g!kQBNCsheJe72w>su@oCDA&0^C#3z8ClX+#BXWJ+Mq>JwrJ)r;h_w2*lKaxQq_R&+~ozpESDt{;Xprl!f6iW8a* zP;U&)Z$<{S#ApfRi&`*%j;txPwlG)wYxXlu5ct9NALf*!V7&lG0Ump1bEMr#<(H#AZs7`0=^+v46}G`a*EzJsMKyVT3yqf9Ks~)Xs^qNMAx!boZTp06o9N^@aRo7Fnf>;`s8Mcdg*xfQR z+rvD(7}G?CFxgkM>tmTlE5ZrMfG#Ma=;-n^GG@DrFag_$h?&I!7z(Q(z>tuFf{cJA zKok)D#SnRsPy)@FMlZmABp^sIAV^3?1Yrpvq8a`hXIo(r*n$Xb=g+V2m$bckVhB2B zOf+GHAtaJWL6H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^iL$?vqp6qB53;l?R3Y$#f!Z_9R;?RMh*AFEEhC4ma=%6;S6 z=eCNtgoXg8$z(R>nY@FWaCmVw(CtUBS-`8wY|9c+me5E!ny@69uqiy{=+GTf8)}1m zoE&vitT0ReA4D7N;3Lq(i=WKi7X2aD8Cu7W@F&4+Gq=v;*R1>I3{KOm~0}vAqSXU_N2(U5s`Wk zq6{bILg(|)T-vx5%82bwf+gqtoLl!t!Q6UJ*6cM1g>y%DpxX5f@D!t zP)w{H#2~ID^!24JZIS4Ni`jK!Gqm z`UIF<84ZuIt;V|PL#UnET2+{2*9eA&0ql3CXvPp}nJL7eK*VfXE~zGqrLJwkuMWAa z&o~R_hSb4aELNl6UEXUWOe(#L#)@{rkr6_TezbdSXR&J4g3^85W!$UC>I|}Y5ZC_QTO$L2iD&N!gN3T?NPg!*pc2UUH4IN5Zn3e>)(|YnL4iubW qVJak>S7X@ctk^1%K})W4`DT#afqiwAiCMOP#oUoj6eI?m^SMAT%1itJ diff --git a/R/ui_elements.R b/R/ui_elements.R index 48a18a6b..798a04ad 100644 --- a/R/ui_elements.R +++ b/R/ui_elements.R @@ -375,6 +375,17 @@ ui_elements <- function(selection) { value = "acc_pan_chars", title = "Settings", icon = bsicons::bs_icon("table"), + # vectorSelectInput( + # inputId = "baseline_theme", + # selected = "none", + # label = i18n$t("Select table theme"), + # choices = c( + # "The Journal of the American Medical Association" = "jama", + # "The Lancet"="lancet", + # "The New England Journal of Medicine" = "nejm", + # "The Quarterly Journal of Economics" = "qjecon") + # ), + shiny::uiOutput("detail_level"), shiny::uiOutput("strat_var"), shiny::helpText(i18n$t("Only factor/categorical variables are available for stratification. Go back to the 'Prepare' tab to reclass a variable if it's not on the list.")), shiny::conditionalPanel( diff --git a/SESSION.md b/SESSION.md index 756f93cd..80527531 100644 --- a/SESSION.md +++ b/SESSION.md @@ -11,11 +11,11 @@ |collate |en_US.UTF-8 | |ctype |en_US.UTF-8 | |tz |Europe/Copenhagen | -|date |2025-10-31 | +|date |2025-11-09 | |rstudio |2025.05.0+496 Mariposa Orchid (desktop) | |pandoc |3.6.4 @ /opt/homebrew/bin/ (via rmarkdown) | |quarto |1.7.30 @ /usr/local/bin/quarto | -|FreesearchR |25.10.5.251031 | +|FreesearchR |25.11.1.251109 | -------------------------------------------------------------------------------- @@ -44,7 +44,6 @@ |cardx |0.2.5 |2025-07-03 |CRAN (R 4.4.1) | |caTools |1.18.3 |2024-09-04 |CRAN (R 4.4.1) | |cellranger |1.1.0 |2016-07-27 |CRAN (R 4.4.0) | -|cffr |1.2.0 |2025-01-25 |CRAN (R 4.4.1) | |checkmate |2.3.2 |2024-07-29 |RSPM (R 4.4.0) | |class |7.3-23 |2025-01-01 |CRAN (R 4.4.1) | |classInt |0.4-11 |2025-01-08 |CRAN (R 4.4.1) | @@ -54,8 +53,6 @@ |colorspace |2.1-1 |2024-07-26 |CRAN (R 4.4.1) | |commonmark |2.0.0 |2025-07-07 |CRAN (R 4.4.1) | |crayon |1.5.3 |2024-06-20 |CRAN (R 4.4.1) | -|crosstalk |1.2.1 |2023-11-23 |CRAN (R 4.4.0) | -|curl |6.4.0 |2025-06-22 |RSPM (R 4.4.0) | |data.table |1.17.8 |2025-07-10 |CRAN (R 4.4.1) | |datamods |1.5.3 |2024-10-02 |CRAN (R 4.4.1) | |datawizard |1.2.0 |2025-07-17 |CRAN (R 4.4.1) | @@ -86,7 +83,7 @@ |foreach |1.5.2 |2022-02-02 |CRAN (R 4.4.0) | |foreign |0.8-90 |2025-03-31 |CRAN (R 4.4.1) | |Formula |1.2-5 |2023-02-24 |CRAN (R 4.4.1) | -|FreesearchR |25.10.5 |NA |NA | +|FreesearchR |25.11.1 |NA |NA | |fs |1.6.6 |2025-04-12 |CRAN (R 4.4.1) | |gdtools |0.4.2 |2025-03-27 |CRAN (R 4.4.1) | |generics |0.1.4 |2025-05-09 |CRAN (R 4.4.1) | @@ -114,11 +111,9 @@ |iterators |1.0.14 |2022-02-05 |CRAN (R 4.4.1) | |jquerylib |0.1.4 |2021-04-26 |CRAN (R 4.4.0) | |jsonlite |2.0.0 |2025-03-27 |CRAN (R 4.4.1) | -|jsonvalidate |1.5.0 |2025-02-07 |CRAN (R 4.4.1) | |KernSmooth |2.23-26 |2025-01-01 |CRAN (R 4.4.1) | |keyring |1.4.1 |2025-06-15 |CRAN (R 4.4.1) | |knitr |1.50 |2025-03-16 |CRAN (R 4.4.1) | -|labeling |0.4.3 |2023-08-29 |CRAN (R 4.4.1) | |later |1.4.2 |2025-04-08 |RSPM (R 4.4.0) | |lattice |0.22-7 |2025-04-02 |CRAN (R 4.4.1) | |lifecycle |1.0.4 |2023-11-07 |CRAN (R 4.4.1) | @@ -163,14 +158,9 @@ |qqconf |1.3.2 |2023-04-14 |CRAN (R 4.4.0) | |qqplotr |0.0.6 |2023-01-25 |CRAN (R 4.4.0) | |quarto |1.5.0 |2025-07-28 |RSPM (R 4.4.0) | -|R.cache |0.17.0 |2025-05-02 |CRAN (R 4.4.1) | -|R.methodsS3 |1.8.2 |2022-06-13 |CRAN (R 4.4.1) | -|R.oo |1.27.1 |2025-05-02 |CRAN (R 4.4.1) | -|R.utils |2.13.0 |2025-02-24 |CRAN (R 4.4.1) | |R6 |2.6.1 |2025-02-15 |CRAN (R 4.4.1) | |ragg |1.4.0 |2025-04-10 |RSPM (R 4.4.0) | |rankinPlot |1.1.0 |2023-01-30 |CRAN (R 4.4.0) | -|rappdirs |0.3.3 |2021-01-31 |CRAN (R 4.4.1) | |rbibutils |2.3 |2024-10-04 |CRAN (R 4.4.1) | |RColorBrewer |1.1-3 |2022-04-03 |CRAN (R 4.4.1) | |Rcpp |1.1.0 |2025-07-02 |CRAN (R 4.4.1) | @@ -209,7 +199,6 @@ |stringi |1.8.7 |2025-03-27 |CRAN (R 4.4.1) | |stringr |1.5.1 |2023-11-14 |RSPM (R 4.4.0) | |stRoke |25.9.2 |2025-09-30 |CRAN (R 4.4.1) | -|styler |1.10.3 |2024-04-07 |CRAN (R 4.4.0) | |systemfonts |1.2.3 |2025-04-30 |CRAN (R 4.4.1) | |testthat |3.2.3 |2025-01-13 |CRAN (R 4.4.1) | |textshaping |1.0.1 |2025-05-01 |RSPM (R 4.4.0) | @@ -224,11 +213,8 @@ |tzdb |0.5.0 |2025-03-15 |CRAN (R 4.4.1) | |urlchecker |1.0.1 |2021-11-30 |CRAN (R 4.4.1) | |usethis |3.1.0 |2024-11-26 |RSPM (R 4.4.0) | -|utf8 |1.2.6 |2025-06-08 |CRAN (R 4.4.1) | |uuid |1.2-1 |2024-07-29 |CRAN (R 4.4.1) | -|V8 |6.0.6 |2025-08-18 |CRAN (R 4.4.1) | |vctrs |0.6.5 |2023-12-01 |CRAN (R 4.4.0) | -|viridisLite |0.4.2 |2023-05-02 |CRAN (R 4.4.1) | |vroom |1.6.5 |2023-12-05 |CRAN (R 4.4.0) | |withr |3.0.2 |2024-10-28 |CRAN (R 4.4.1) | |writexl |1.5.4 |2025-04-15 |CRAN (R 4.4.1) | diff --git a/app_docker/app.R b/app_docker/app.R index 21c246e1..0f193d1d 100644 --- a/app_docker/app.R +++ b/app_docker/app.R @@ -1,7 +1,7 @@ ######## -#### Current file: /var/folders/9l/xbc19wxx0g79jdd2sf_0v291mhwh7f/T//RtmpigVRui/file787d121e91b3.R +#### Current file: /var/folders/9l/xbc19wxx0g79jdd2sf_0v291mhwh7f/T//RtmpFr1XvR/file15f634a33505f.R ######## i18n_path <- here::here("translations") @@ -62,7 +62,7 @@ i18n$set_translation_language("en") #### Current file: /Users/au301842/FreesearchR/R//app_version.R ######## -app_version <- function()'25.10.5' +app_version <- function()'25.11.1' ######## @@ -83,7 +83,6 @@ app_version <- function()'25.10.5' #' mtcars |> baseline_table() #' mtcars |> baseline_table(fun.args = list(by = "gear")) baseline_table <- function(data, fun.args = NULL, fun = gtsummary::tbl_summary, vars = NULL) { - out <- do.call(fun, c(list(data = data), fun.args)) return(out) } @@ -94,19 +93,26 @@ baseline_table <- function(data, fun.args = NULL, fun = gtsummary::tbl_summary, #' #' @param data data #' @param ... passed as fun.arg to baseline_table() -#' @param strat.var grouping/strat variable #' @param add.p add comparison/p-value #' @param add.overall add overall column +#' @param by.var specify stratification variable +#' @param theme set table theme +#' @param detail_level specify detail level. Either "minimal" or "extended". #' #' @returns gtsummary table list object #' @export #' #' @examples #' mtcars |> create_baseline(by.var = "gear", add.p = "yes" == "yes") +#' mtcars |> create_baseline(by.var = "gear", detail_level = "extended") +#' mtcars |> create_baseline(by.var = "gear", detail_level = "extended",type = list(gtsummary::all_dichotomous() ~ "categorical"),theme="nejm") +#' #' create_baseline(default_parsing(mtcars), by.var = "am", add.p = FALSE, add.overall = FALSE, theme = "lancet") -create_baseline <- function(data, ..., by.var, add.p = FALSE, add.overall = FALSE, theme = c("jama", "lancet", "nejm", "qjecon")) { +create_baseline <- function(data, ..., by.var, add.p = FALSE, add.overall = FALSE, theme = c("jama", "lancet", "nejm", "qjecon"), detail_level = c("minimal", "extended")) { theme <- match.arg(theme) + detail_level <- match.arg(detail_level) + if (by.var == "none" | !by.var %in% names(data)) { by.var <- NULL } @@ -124,11 +130,32 @@ create_baseline <- function(data, ..., by.var, add.p = FALSE, add.overall = FALS args <- list(...) + # browser() + + if (!any(hasName(args, c("type", "statistic")))) { + if (detail_level == "extended") { + args <- + modifyList( + args, + list( + type = list(gtsummary::all_continuous() ~ "continuous2", + gtsummary::all_dichotomous() ~ "categorical"), + statistic = list(gtsummary::all_continuous() ~ c( + "{median} ({p25}, {p75})", + "{mean} ({sd})", + "{min}, {max}")) + ) + ) + } + } + parameters <- list( data = data, - fun.args = list(by = by.var, ...) + fun.args = purrr::list_flatten(list(by = by.var, args)) ) + + # browser() out <- do.call( baseline_table, parameters @@ -4274,7 +4301,7 @@ data_types <- function() { #### Current file: /Users/au301842/FreesearchR/R//hosted_version.R ######## -hosted_version <- function()'v25.10.5-251031' +hosted_version <- function()'v25.11.1-251109' ######## @@ -9914,6 +9941,17 @@ ui_elements <- function(selection) { value = "acc_pan_chars", title = "Settings", icon = bsicons::bs_icon("table"), + # vectorSelectInput( + # inputId = "baseline_theme", + # selected = "none", + # label = i18n$t("Select table theme"), + # choices = c( + # "The Journal of the American Medical Association" = "jama", + # "The Lancet"="lancet", + # "The New England Journal of Medicine" = "nejm", + # "The Quarterly Journal of Economics" = "qjecon") + # ), + shiny::uiOutput("detail_level"), shiny::uiOutput("strat_var"), shiny::helpText(i18n$t("Only factor/categorical variables are available for stratification. Go back to the 'Prepare' tab to reclass a variable if it's not on the list.")), shiny::conditionalPanel( @@ -13201,7 +13239,7 @@ server <- function(input, output, session) { columnSelectInput( inputId = "strat_var", selected = "none", - label = "Select variable to stratify baseline", + label = i18n$t("Select variable to stratify baseline"), data = shiny::reactive(rv$data_filtered)(), col_subset = c( "none", @@ -13210,6 +13248,37 @@ server <- function(input, output, session) { ) }) + # output$baseline_theme <- shiny::renderUI({ + # choices <- + # + # vectorSelectInput( + # inputId = "baseline_theme", + # selected = "none", + # label = i18n$t("Select table theme"), + # choices = c( + # "The Journal of the American Medical Association" = "jama", + # "The Lancet"="lancet", + # "The New England Journal of Medicine" = "nejm", + # "The Quarterly Journal of Economics" = "qjecon") + # ) + # }) + + + output$detail_level <- shiny::renderUI({ + shiny::radioButtons( + inputId = "detail_level", + label = i18n$t("Level of detail"), + selected = "minimal", + inline = TRUE,choiceValues = c("minimal", + "extended"), + choiceNames = c( + i18n$t("Minimal"), + i18n$t("Extensive") + ) + ) + }) + + ############################################################################## ######### ######### Descriptive evaluations @@ -13235,30 +13304,39 @@ server <- function(input, output, session) { # }) + + shiny::observeEvent( list( input$act_eval ), { shiny::req(input$strat_var) + # shiny::req(input$baseline_theme) + shiny::req(input$detail_level) shiny::req(rv$list$data) + + parameters <- list( by.var = input$strat_var, add.p = input$add_p == "yes", - add.overall = TRUE + add.overall = TRUE, + # theme = input$baseline_theme, + detail_level = input$detail_level ) ## Limits maximum number of levels included in baseline table to 20. data <- rv$list$data |> lapply(\(.x){ # browser() - if (is.factor(.x)){ - cut_var(.x,breaks=20,type="top") + if (is.factor(.x)) { + cut_var(.x, breaks = 20, type = "top") } else { .x } - }) |> dplyr::bind_cols() + }) |> + dplyr::bind_cols() # Attempt to introduce error on analysing too large dataset # tryCatch( diff --git a/app_docker/translations/translation_da.csv b/app_docker/translations/translation_da.csv index 22cafcfa..6f697a07 100644 --- a/app_docker/translations/translation_da.csv +++ b/app_docker/translations/translation_da.csv @@ -291,3 +291,7 @@ "Create relative stacked barplots to show the distribution of categorical levels","Create relative stacked barplots to show the distribution of categorical levels" "Side-by-side barplot","Side-by-side barplot" "Create side-by-side barplot to show the distribution of categorical levels","Create side-by-side barplot to show the distribution of categorical levels" +"Select table theme","Select table theme" +"Level of detail","Level of detail" +"Minimal","Minimal" +"Extensive","Extensive" diff --git a/app_docker/translations/translation_de.csv b/app_docker/translations/translation_de.csv index d8947867..54a25983 100644 --- a/app_docker/translations/translation_de.csv +++ b/app_docker/translations/translation_de.csv @@ -291,3 +291,7 @@ "Create relative stacked barplots to show the distribution of categorical levels","Create relative stacked barplots to show the distribution of categorical levels" "Side-by-side barplot","Side-by-side barplot" "Create side-by-side barplot to show the distribution of categorical levels","Create side-by-side barplot to show the distribution of categorical levels" +"Select table theme","Select table theme" +"Level of detail","Level of detail" +"Minimal","Minimal" +"Extensive","Extensive" diff --git a/app_docker/translations/translation_sv.csv b/app_docker/translations/translation_sv.csv index b9e18015..99bed52e 100644 --- a/app_docker/translations/translation_sv.csv +++ b/app_docker/translations/translation_sv.csv @@ -291,3 +291,7 @@ "Create relative stacked barplots to show the distribution of categorical levels","Create relative stacked barplots to show the distribution of categorical levels" "Side-by-side barplot","Side-by-side barplot" "Create side-by-side barplot to show the distribution of categorical levels","Create side-by-side barplot to show the distribution of categorical levels" +"Select table theme","Select table theme" +"Level of detail","Level of detail" +"Minimal","Minimal" +"Extensive","Extensive" diff --git a/app_docker/translations/translation_sw.csv b/app_docker/translations/translation_sw.csv index 70d1fe1c..d94b1894 100644 --- a/app_docker/translations/translation_sw.csv +++ b/app_docker/translations/translation_sw.csv @@ -291,3 +291,7 @@ "Create relative stacked barplots to show the distribution of categorical levels","Create relative stacked barplots to show the distribution of categorical levels" "Side-by-side barplot","Side-by-side barplot" "Create side-by-side barplot to show the distribution of categorical levels","Create side-by-side barplot to show the distribution of categorical levels" +"Select table theme","Select table theme" +"Level of detail","Level of detail" +"Minimal","Minimal" +"Extensive","Extensive" diff --git a/inst/translations/translation_da.csv b/inst/translations/translation_da.csv index 22cafcfa..6f697a07 100644 --- a/inst/translations/translation_da.csv +++ b/inst/translations/translation_da.csv @@ -291,3 +291,7 @@ "Create relative stacked barplots to show the distribution of categorical levels","Create relative stacked barplots to show the distribution of categorical levels" "Side-by-side barplot","Side-by-side barplot" "Create side-by-side barplot to show the distribution of categorical levels","Create side-by-side barplot to show the distribution of categorical levels" +"Select table theme","Select table theme" +"Level of detail","Level of detail" +"Minimal","Minimal" +"Extensive","Extensive" diff --git a/inst/translations/translation_de.csv b/inst/translations/translation_de.csv index d8947867..54a25983 100644 --- a/inst/translations/translation_de.csv +++ b/inst/translations/translation_de.csv @@ -291,3 +291,7 @@ "Create relative stacked barplots to show the distribution of categorical levels","Create relative stacked barplots to show the distribution of categorical levels" "Side-by-side barplot","Side-by-side barplot" "Create side-by-side barplot to show the distribution of categorical levels","Create side-by-side barplot to show the distribution of categorical levels" +"Select table theme","Select table theme" +"Level of detail","Level of detail" +"Minimal","Minimal" +"Extensive","Extensive" diff --git a/inst/translations/translation_sv.csv b/inst/translations/translation_sv.csv index b9e18015..99bed52e 100644 --- a/inst/translations/translation_sv.csv +++ b/inst/translations/translation_sv.csv @@ -291,3 +291,7 @@ "Create relative stacked barplots to show the distribution of categorical levels","Create relative stacked barplots to show the distribution of categorical levels" "Side-by-side barplot","Side-by-side barplot" "Create side-by-side barplot to show the distribution of categorical levels","Create side-by-side barplot to show the distribution of categorical levels" +"Select table theme","Select table theme" +"Level of detail","Level of detail" +"Minimal","Minimal" +"Extensive","Extensive" diff --git a/inst/translations/translation_sw.csv b/inst/translations/translation_sw.csv index 70d1fe1c..d94b1894 100644 --- a/inst/translations/translation_sw.csv +++ b/inst/translations/translation_sw.csv @@ -291,3 +291,7 @@ "Create relative stacked barplots to show the distribution of categorical levels","Create relative stacked barplots to show the distribution of categorical levels" "Side-by-side barplot","Side-by-side barplot" "Create side-by-side barplot to show the distribution of categorical levels","Create side-by-side barplot to show the distribution of categorical levels" +"Select table theme","Select table theme" +"Level of detail","Level of detail" +"Minimal","Minimal" +"Extensive","Extensive" diff --git a/man/create_baseline.Rd b/man/create_baseline.Rd index 4c13ff3c..df159590 100644 --- a/man/create_baseline.Rd +++ b/man/create_baseline.Rd @@ -10,7 +10,8 @@ create_baseline( by.var, add.p = FALSE, add.overall = FALSE, - theme = c("jama", "lancet", "nejm", "qjecon") + theme = c("jama", "lancet", "nejm", "qjecon"), + detail_level = c("minimal", "extended") ) } \arguments{ @@ -18,11 +19,15 @@ create_baseline( \item{...}{passed as fun.arg to baseline_table()} +\item{by.var}{specify stratification variable} + \item{add.p}{add comparison/p-value} \item{add.overall}{add overall column} -\item{strat.var}{grouping/strat variable} +\item{theme}{set table theme} + +\item{detail_level}{specify detail level. Either "minimal" or "extended".} } \value{ gtsummary table list object @@ -32,5 +37,8 @@ Create a baseline table } \examples{ mtcars |> create_baseline(by.var = "gear", add.p = "yes" == "yes") +mtcars |> create_baseline(by.var = "gear", detail_level = "extended") +mtcars |> create_baseline(by.var = "gear", detail_level = "extended",type = list(gtsummary::all_dichotomous() ~ "categorical"),theme="nejm") + create_baseline(default_parsing(mtcars), by.var = "am", add.p = FALSE, add.overall = FALSE, theme = "lancet") }