Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #2468 fix_derive_vars_crit_flag: create integer flag #2618

Merged
merged 6 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions R/derive_vars_crit_flag.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions tests/testthat/test-derive_vars_crit_flag.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
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, ~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(
Expand Down
Loading