Skip to content

Commit

Permalink
#2468 fix_derive_vars_crit_flag: create correct numeric flag (CRITyFN…
Browse files Browse the repository at this point in the history
… instead of CRITyFLN)
  • Loading branch information
bundfussr committed Dec 19, 2024
1 parent ef04a31 commit 93483fa
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- New function `derive_vars_cat()` for deriving pairs of variables or more, e.g.
`AVALCATy` & `AVALCAyN`. (#2480)
- New function `derive_vars_crit_flag()` for deriving criterion flag variables
(`CRITy`, `CRITyFL`, `CRITyFLN`). (#2468)
(`CRITy`, `CRITyFL`, `CRITyFN`). (#2468)
- New function `transform_range()` to transform values from a source range to a
target range. (#2571)
- Replace use of `data("sdtm")` with `sdtm <- pharmaverse::sdtm` in templates and vignettes. (#2498)
Expand Down
14 changes: 7 additions & 7 deletions R/derive_vars_crit_flag.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Derive Criterion Flag Variables `CRITy`, `CRITyFL`, and `CRITyFLN`
#' Derive Criterion Flag Variables `CRITy`, `CRITyFL`, and `CRITyFN`
#'
#' @description
#'
Expand Down Expand Up @@ -49,12 +49,12 @@
#' *Permitted Values*: `TRUE`, `FALSE`
#' @param create_numeric_flag Create a numeric flag?
#'
#' If set to `TRUE`, the `CRITyFLN` variable is created. It is set to `1` if
#' If set to `TRUE`, the `CRITyFN` variable is created. It is set to `1` if
#' `CRITyFL == "Y"`, it set to `0` if `CRITyFL == "N"`, and to `NA` otherwise.
#'
#' *Permitted Values*: `TRUE`, `FALSE`
#' @return The input dataset with the variables `CRITy`, `CRITyFL`, and
#' optionally `CRITyFLN` added.
#' optionally `CRITyFN` added.
#'
#' @family der_bds_findings
#' @keywords der_bds_findings
Expand Down Expand Up @@ -110,10 +110,10 @@ derive_vars_crit_flag <- function(dataset,

if (values_yn) {
crityfl_no <- "N"
crityfln_no <- 0L
crityfb_no <- 0L
} else {
crityfl_no <- NA_character_
crityfln_no <- NA_integer_
crityfb_no <- NA_integer_
}

tryCatch(
Expand Down Expand Up @@ -154,9 +154,9 @@ derive_vars_crit_flag <- function(dataset,
)

if (create_numeric_flag) {
new_critflnvar <- paste0("CRIT", as.character(crit_nr), "FLN")
new_critfbvar <- paste0("CRIT", as.character(crit_nr), "FN")
dataset <- dataset %>% mutate(
!!new_critflnvar := yn_to_numeric(!!sym(new_critflvar))
!!new_critfbvar := yn_to_numeric(!!sym(new_critflvar))
)
}
dataset
Expand Down
6 changes: 3 additions & 3 deletions man/derive_vars_crit_flag.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions tests/testthat/test-derive_vars_crit_flag.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ 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, ~CRIT1FLN, ~CRIT1,
~AVAL, ~CRIT1FL, ~CRIT1FN, ~CRIT1,
23, NA_character_, NA_real_, NA_character_,
42, "Y", 1, "AVAL > 40",
NA, NA_character_, NA_real_, NA_character_
Expand All @@ -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, ~CRIT2FLN, ~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", 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",
)

expect_dfs_equal(
Expand Down

0 comments on commit 93483fa

Please sign in to comment.