From 187c977f90ff76cc56ee9b5936477715c54a8349 Mon Sep 17 00:00:00 2001 From: Stefan Bundfuss <80953585+bundfussr@users.noreply.github.com> Date: Fri, 20 Dec 2024 14:52:59 +0100 Subject: [PATCH 1/2] Closes #2468 fix_derive_vars_crit_flag: create integer flag (#2618) * #2468 fix_derive_vars_crit_flag: create correct numeric flag (CRITyFN instead of CRITyFLN) * #2468 fix_derive_vars_crit_flag: update vignettes * #2468 fix_derive_vars_crit_flag: style files * #2468 fix_derive_vars_crit_flag: fix typo in variable names * #2468 fix_derive_vars_crit_flag: create integer flag --- R/derive_vars_crit_flag.R | 4 +--- tests/testthat/test-derive_vars_crit_flag.R | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/R/derive_vars_crit_flag.R b/R/derive_vars_crit_flag.R index eeebe2d868..b988fc8740 100644 --- a/R/derive_vars_crit_flag.R +++ b/R/derive_vars_crit_flag.R @@ -110,10 +110,8 @@ derive_vars_crit_flag <- function(dataset, if (values_yn) { crityfl_no <- "N" - crityfn_no <- 0L } else { crityfl_no <- NA_character_ - crityfn_no <- NA_integer_ } tryCatch( @@ -156,7 +154,7 @@ derive_vars_crit_flag <- function(dataset, if (create_numeric_flag) { new_critfnvar <- paste0("CRIT", as.character(crit_nr), "FN") dataset <- dataset %>% mutate( - !!new_critfnvar := yn_to_numeric(!!sym(new_critflvar)) + !!new_critfnvar := as.integer(yn_to_numeric(!!sym(new_critflvar))) ) } dataset diff --git a/tests/testthat/test-derive_vars_crit_flag.R b/tests/testthat/test-derive_vars_crit_flag.R index dbd0708da8..e386bb44cb 100644 --- a/tests/testthat/test-derive_vars_crit_flag.R +++ b/tests/testthat/test-derive_vars_crit_flag.R @@ -21,10 +21,10 @@ test_that("derive_vars_crit_flag Test 1: works with defaults", { ## Test 2: create numeric flag ---- test_that("derive_vars_crit_flag Test 2: create numeric flag", { expected <- tibble::tribble( - ~AVAL, ~CRIT1FL, ~CRIT1FN, ~CRIT1, - 23, NA_character_, NA_real_, NA_character_, - 42, "Y", 1, "AVAL > 40", - NA, NA_character_, NA_real_, NA_character_ + ~AVAL, ~CRIT1FL, ~CRIT1FN, ~CRIT1, + 23, NA_character_, NA_integer_, NA_character_, + 42, "Y", 1L, "AVAL > 40", + NA, NA_character_, NA_integer_, NA_character_ ) expect_dfs_equal( @@ -42,12 +42,12 @@ test_that("derive_vars_crit_flag Test 2: create numeric flag", { ## Test 3: using values Y and N ---- test_that("derive_vars_crit_flag Test 3: using values Y and N", { expected <- tibble::tribble( - ~PARAMCD, ~AVAL, ~CRIT2FL, ~CRIT2FN, ~CRIT2, - "AST", 23, "N", 0, "AST > 40", - "AST", 42, "Y", 1, "AST > 40", - "AST", NA, NA_character_, NA_real_, "AST > 40", - "ALT", 26, "N", 0, "ALT > 40", - "ALT", 56, "Y", 1, "ALT > 40", + ~PARAMCD, ~AVAL, ~CRIT2FL, ~CRIT2FN, ~CRIT2, + "AST", 23, "N", 0L, "AST > 40", + "AST", 42, "Y", 1L, "AST > 40", + "AST", NA, NA_character_, NA_integer_, "AST > 40", + "ALT", 26, "N", 0L, "ALT > 40", + "ALT", 56, "Y", 1L, "ALT > 40" ) expect_dfs_equal( From f9f0492d605a7530fe029f24af4ecb8d88cbca4f Mon Sep 17 00:00:00 2001 From: bundfussr Date: Fri, 20 Dec 2024 13:53:49 +0000 Subject: [PATCH 2/2] [skip actions] Bump version to 1.1.1.9044 --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 2bd546bb77..7d6809a257 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: admiral Title: ADaM in R Asset Library -Version: 1.1.1.9043 +Version: 1.1.1.9044 Authors@R: c( person("Ben", "Straub", , "ben.x.straub@gsk.com", role = c("aut", "cre")), person("Stefan", "Bundfuss", role = "aut",