From 0fb3ec3264dc081e8178aae1bc623567acb64901 Mon Sep 17 00:00:00 2001 From: Emily de la Rua Date: Fri, 7 Jul 2023 18:05:30 -0400 Subject: [PATCH] Add tests, fix spelling --- R/count_patients_with_flags.R | 2 +- man/count_patients_with_flags.Rd | 2 +- .../_snaps/count_patients_with_flags.md | 52 +++++++++++++++++++ .../testthat/test-count_patients_with_flags.R | 7 ++- 4 files changed, 57 insertions(+), 6 deletions(-) diff --git a/R/count_patients_with_flags.R b/R/count_patients_with_flags.R index bf24c4ccb9..a4a03d5245 100644 --- a/R/count_patients_with_flags.R +++ b/R/count_patients_with_flags.R @@ -21,7 +21,7 @@ NULL #' @param flag_labels (`character`)\cr vector of labels to use for flag variables. #' #' @note If `flag_labels` is not specified, variables labels will be extracted from `df`. If variables are not -#' labelled, variable names will be used instead. Alternatively, a named `vector` can be supplied to +#' labeled, variable names will be used instead. Alternatively, a named `vector` can be supplied to #' `flag_variables` such that within each name-value pair the name corresponds to the variable name and the value is #' the label to use for this variable. #' diff --git a/man/count_patients_with_flags.Rd b/man/count_patients_with_flags.Rd index 0dd05be80b..77f97d28c6 100644 --- a/man/count_patients_with_flags.Rd +++ b/man/count_patients_with_flags.Rd @@ -116,7 +116,7 @@ arguments and additional format arguments. This function is a wrapper for \code{ }} \note{ If \code{flag_labels} is not specified, variables labels will be extracted from \code{df}. If variables are not -labelled, variable names will be used instead. Alternatively, a named \code{vector} can be supplied to +labeled, variable names will be used instead. Alternatively, a named \code{vector} can be supplied to \code{flag_variables} such that within each name-value pair the name corresponds to the variable name and the value is the label to use for this variable. } diff --git a/tests/testthat/_snaps/count_patients_with_flags.md b/tests/testthat/_snaps/count_patients_with_flags.md index 4d72632aae..875c4b2b03 100644 --- a/tests/testthat/_snaps/count_patients_with_flags.md +++ b/tests/testthat/_snaps/count_patients_with_flags.md @@ -101,3 +101,55 @@ Grade 3-5 AE 47 (68.1%) 46 (63.0%) 41 (70.7%) Grade 4/5 AE 34 (49.3%) 38 (52.1%) 32 (55.2%) +# Custom variable label behaviour works + + Code + res + Output + A: Drug X B: Placebo C: Combination + ————————————————————————————————————————————————————————————————————————————————————— + Total number of patients with at least one + SER 45 (65.2%) 46 (63.0%) 37 (63.8%) + REL 49 (71.0%) 48 (65.8%) 40 (69.0%) + CTC35 47 (68.1%) 46 (63.0%) 41 (70.7%) + CTC45 34 (49.3%) 38 (52.1%) 32 (55.2%) + +--- + + Code + res + Output + A: Drug X B: Placebo C: Combination + ————————————————————————————————————————————————————————————————————————————————————— + Total number of patients with at least one + Serious AE 45 (65.2%) 46 (63.0%) 37 (63.8%) + Related AE 49 (71.0%) 48 (65.8%) 40 (69.0%) + Grade 3-5 AE 47 (68.1%) 46 (63.0%) 41 (70.7%) + Grade 4/5 AE 34 (49.3%) 38 (52.1%) 32 (55.2%) + +--- + + Code + res + Output + A: Drug X B: Placebo C: Combination + ————————————————————————————————————————————————————————————————————————————————————— + Total number of patients with at least one + Category 1 45 (65.2%) 46 (63.0%) 37 (63.8%) + Category 2 49 (71.0%) 48 (65.8%) 40 (69.0%) + Category 3 47 (68.1%) 46 (63.0%) 41 (70.7%) + Category 4 34 (49.3%) 38 (52.1%) 32 (55.2%) + +--- + + Code + res + Output + A: Drug X B: Placebo C: Combination + ————————————————————————————————————————————————————————————————————————————————————— + Total number of patients with at least one + Serious AE 45 (65.2%) 46 (63.0%) 37 (63.8%) + Related AE 49 (71.0%) 48 (65.8%) 40 (69.0%) + Grade 3-5 AE 47 (68.1%) 46 (63.0%) 41 (70.7%) + Grade 4/5 AE 34 (49.3%) 38 (52.1%) 32 (55.2%) + diff --git a/tests/testthat/test-count_patients_with_flags.R b/tests/testthat/test-count_patients_with_flags.R index de05eec937..e766919693 100644 --- a/tests/testthat/test-count_patients_with_flags.R +++ b/tests/testthat/test-count_patients_with_flags.R @@ -168,7 +168,7 @@ testthat::test_that("Custom variable label behaviour works", { CTC35 = AETOXGR %in% c("3", "4", "5"), CTC45 = AETOXGR %in% c("4", "5") ) - columns <- c("SER", "REL", "CTC35", "CTC45") + aesi_vars <- c("SER", "REL", "CTC35", "CTC45") # No variable labels (variable names used) lyt <- basic_table() %>% @@ -186,10 +186,9 @@ testthat::test_that("Custom variable label behaviour works", { testthat::expect_snapshot(res) labels <- c("Serious AE", "Related AE", "Grade 3-5 AE", "Grade 4/5 AE") - for (i in seq_along(columns)) { - attr(adae_local[[columns[i]]], "label") <- labels[i] + for (i in seq_along(aesi_vars)) { + attr(adae_local[[aesi_vars[i]]], "label") <- labels[i] } - aesi_vars <- c("SER", "REL", "CTC35", "CTC45") # Variable labels from df lyt <- basic_table() %>%