diff --git a/DESCRIPTION b/DESCRIPTION index 64578c4d..4ea7f6b1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: visR Title: Clinical Graphs and Tables Adhering to Graphical Principles -Version: 0.2.0.9003 +Version: 0.2.0.9004 Authors@R: c( person(given = "Mark", family = "Baillie", @@ -101,6 +101,6 @@ VignetteBuilder: biocViews: Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.1.2 +RoxygenNote: 7.2.0 LazyData: true Language: en-US diff --git a/NEWS.md b/NEWS.md index 86a71b94..d55352b5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,6 +11,7 @@ ### Other Updates * Stratifying variable names have been removed from legend in `visr.survfit()` figures, and the legend title now describes the stratifying variable(s). (#343) * `add_risktable` has a rowgutter argument to allow spacing between plot and risktables +* The strata variable is now removed from the body of `tableone()` results. (#254) * Improved documentation for `visr()` and other generic functions. (#301) diff --git a/R/get_tableone.R b/R/get_tableone.R index 2e2d4747..c5b1d97f 100644 --- a/R/get_tableone.R +++ b/R/get_tableone.R @@ -84,7 +84,9 @@ get_tableone.default <- function(data, strata = NULL, overall=TRUE, summary_func summary_FUN <- match.fun(summary_function) if(overall & !is.null(strata)){ - overall_table1 <- get_tableone(data, strata = NULL, overall = FALSE, summary_function = summary_function) + overall_table1 <- get_tableone(data, strata = NULL, overall = FALSE, summary_function = summary_function) %>% + dplyr::filter(!(variable %in% strata)) + combine_dfs <- TRUE } else{ diff --git a/README.md b/README.md index 6a5709ed..577aac86 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ coverage](https://codecov.io/gh/openpharma/visR/branch/develop/graph/badge.svg)] [![pkgdown](https://github.com/openpharma/visR/actions/workflows/makedocs.yml/badge.svg)](https://github.com/openpharma/visR/actions/workflows/makedocs.yml) [![CRAN status](https://www.r-pkg.org/badges/version/visR)](https://CRAN.R-project.org/package=visR) - + ## Installation diff --git a/inst/WORDLIST b/inst/WORDLIST index cd3b5ed0..f4948e53 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -12,6 +12,7 @@ Chisq Codecov Covid DT +FFFFFF Kaplan Karnakata Lifecycle @@ -65,19 +66,26 @@ io kable linetype magrittr +md mskcc +nums openpharma pkgdown psp pst purrr pvalue +px repo +rgba +rgmrgujyos riskmetric risktable risktables rowgutter rtf +sourcenote +sourcenotes src statlist strata's @@ -86,9 +94,11 @@ stype survdiff survfit tableone +td th tibble tidycmprsk +uncert visR's visualisation visualisations diff --git a/man/visR-package.Rd b/man/visR-package.Rd index fa3793e4..5038986a 100644 --- a/man/visR-package.Rd +++ b/man/visR-package.Rd @@ -6,9 +6,9 @@ \alias{visR-package} \title{visR: Clinical Graphs and Tables Adhering to Graphical Principles} \description{ -\if{html}{\figure{logo.png}{options: align='right' alt='logo' width='120'}} +\if{html}{\figure{logo.png}{options: style='float: right' alt='logo' width='120'}} -To enable fit-for-purpose, reusable clinical and medical research focused visualizations and tables with sensible defaults and based on graphical principles as described in: "Vandemeulebroecke et al. (2018)" , "Vandemeulebroecke et al. (2019)" , and "Morris et al. (2019)" . +To enable fit-for-purpose, reusable clinical and medical research focused visualizations and tables with sensible defaults and based on graphical principles as described in: "Vandemeulebroecke et al. (2018)" \doi{10.1002/pst.1912}, "Vandemeulebroecke et al. (2019)" \doi{10.1002/psp4.12455}, and "Morris et al. (2019)" \doi{10.1136/bmjopen-2019-030215}. } \seealso{ Useful links: diff --git a/tests/testthat/test-get_tableone.R b/tests/testthat/test-get_tableone.R index fe292e9e..7778844d 100644 --- a/tests/testthat/test-get_tableone.R +++ b/tests/testthat/test-get_tableone.R @@ -24,6 +24,9 @@ #' T4.3 An error when the `summary_function` is a function not build for it #' T4.4 An error when the `summary_function` is `summarize_long` #' T4.5 No error when the `summary_function` is `summarize_short` +#' T5. The tableone removes strata variables in rows that leads NA values +#' T5.1 An error when the the table includes one strata variable +#' T5.2 An error when the the table includes multiple strata variables # Requirement T1 ---------------------------------------------------------- @@ -39,7 +42,7 @@ testthat::test_that("T1.1. No error when `data` is of class `data.frame`", { testthat::test_that("T1.2. No error when `data` is of class `tibble`", { data <- dplyr::as_tibble(adtte) - + testthat::expect_error(visR::get_tableone(data = data), NA) }) @@ -47,10 +50,10 @@ testthat::test_that("T1.2. No error when `data` is of class `tibble`", { testthat::test_that("T1.3 No error when `data` is of class `data.table`", { if (nzchar(find.package("data.table"))) { - + data <- data.table::as.data.table(adtte) testthat::expect_error(visR::get_tableone(data = data), NA) - + } }) @@ -85,7 +88,7 @@ testthat::test_that("T2.2 An error when `strata` is a string that is not a colna testthat::test_that("T2.3 Additional colnames in the tableone are the `strata` values (for one `strata`)", { - trtp_colnames <- colnames(visR::get_tableone(data = adtte, + trtp_colnames <- colnames(visR::get_tableone(data = adtte, strata = c("TRTP")))[4:6] testthat::expect_equal(trtp_colnames, levels(adtte$TRTP)) @@ -93,10 +96,10 @@ testthat::test_that("T2.3 Additional colnames in the tableone are the `strata` v testthat::test_that("T2.4 Additional colnames in the tableone are the crossproduct of all `strata` values (for more than one `strata`)", { - mapply_colnames <- c(mapply(function(x, y) paste(x, y, sep = "_"), + mapply_colnames <- c(mapply(function(x, y) paste(x, y, sep = "_"), levels(adtte$TRTP), MoreArgs = list(levels(adtte$SEX)))) - visR_colnames <- colnames(visR::get_tableone(data = adtte, + visR_colnames <- colnames(visR::get_tableone(data = adtte, strata = c("TRTP", "SEX")))[4:9] testthat::expect_equal(mapply_colnames, visR_colnames) @@ -107,30 +110,30 @@ testthat::test_that("T2.4 Additional colnames in the tableone are the crossprodu testthat::context("get_tableone - T3. The tableone includes expected columnnames") testthat::test_that("T3.1 Tableone by default includes columns `variable`, `statistic`, and `Total`", { - + tableone_colnames <- colnames(visR::get_tableone(data = adtte)) - + testthat::expect_equal(tableone_colnames, c("variable", "statistic", "Total")) }) testthat::test_that("T3.2 Tableone still includes the colum `Total` if `overall` is FALSE but no `strata` is given", { - + tableone_colnames <- colnames(visR::get_tableone(data = adtte, overall = FALSE)) - + testthat::expect_equal(tableone_colnames, c("variable", "statistic", "Total")) }) testthat::test_that("T3.3 Tableone does not include the colum `Total` if `overall` is FALSE and a `strata` is given", { - tblone_colnames <- colnames(visR::get_tableone(data = adtte, - overall = FALSE, + tblone_colnames <- colnames(visR::get_tableone(data = adtte, + overall = FALSE, strata = c("TRTP"))) - - testthat::expect_equal(tblone_colnames, + + testthat::expect_equal(tblone_colnames, c("variable", "statistic", levels(adtte$TRTP))) - + }) # Requirement T4 --------------------------------------------------------------- @@ -139,28 +142,28 @@ testthat::context("get_tableone - T4. The function only accepts suitable summary testthat::test_that("T4.1 An error when the `summary_function` is NULL", { - testthat::expect_error(visR::get_tableone(data = adtte, + testthat::expect_error(visR::get_tableone(data = adtte, summary_function = NULL)) }) testthat::test_that("T4.2 An error when the `summary_function` is a string", { - testthat::expect_error(visR::get_tableone(data = adtte, + testthat::expect_error(visR::get_tableone(data = adtte, summary_function = "A")) }) testthat::test_that("T4.3 An error when the `summary_function` is a function not build for it", { - testthat::expect_error(visR::get_tableone(data = adtte, + testthat::expect_error(visR::get_tableone(data = adtte, summary_function = sum)) }) testthat::test_that("T4.4 An error when the `summary_function` is `summarize_long`", { - testthat::expect_error(visR::get_tableone(data = adtte, + testthat::expect_error(visR::get_tableone(data = adtte, summary_function = summarize_long)) }) @@ -168,9 +171,40 @@ testthat::test_that("T4.4 An error when the `summary_function` is `summarize_lon testthat::test_that("T4.5 No error when the `summary_function` is `summarize_short`", { - testthat::expect_error(visR::get_tableone(data = adtte, + testthat::expect_error(visR::get_tableone(data = adtte, summary_function = summarize_short), NA) }) +# Requirement T5 --------------------------------------------------------------- + +testthat::context("get_tableone - T5. The tableone removes strata variables in rows that leads NA values") + +testthat::test_that("T5.1 An error when the the table includes one strata variable", { + + strata <- c("SEX") + + table <- adtte %>% + visR::get_tableone(strata = strata) + + testthat::expect_true(sum(strata %in% unique(table$variable)) == 0) + +}) + +testthat::test_that("T5.2 An error when the the table includes multiple strata variables", { + + strata <- c("SEX", "RACE") + + table <- adtte %>% + visR::get_tableone(strata = strata) + + testthat::expect_true(sum(strata %in% unique(table$variable)) == 0) + + table <- adtte %>% + visR::get_tableone(strata = strata, overall = FALSE) + + testthat::expect_true(sum(strata %in% unique(table$variable)) == 0) + +}) + # END OF CODE -------------------------------------------------------------