Skip to content

Commit

Permalink
fix template
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanThoma committed Sep 25, 2024
1 parent e98c228 commit ab4390b
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 42 deletions.
24 changes: 11 additions & 13 deletions inst/templates/ad_adeg.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ range_lookup <- tibble::tribble(

# Assign AVALCAx
avalcax_lookup <- exprs(
~PARAMCD, ~condition, ~AVALCAT1, ~AVALCA1N,
"QT", AVAL <= 450, "<= 450 msec", 1,
"QT", AVAL > 450 & AVAL <= 480, ">450<=480 msec", 2,
"QT", AVAL > 480 & AVAL <= 500, ">480<=500 msec", 3,
"QT", AVAL > 500, ">500 msec", 4
~condition, ~AVALCAT1, ~AVALCA1N,
starts_with(PARAMCD, "QT") & AVAL <= 450, "<= 450 msec", 1,
starts_with(PARAMCD, "QT") & AVAL > 450 & AVAL <= 480, ">450<=480 msec", 2,
starts_with(PARAMCD, "QT") & AVAL > 480 & AVAL <= 500, ">480<=500 msec", 3,
starts_with(PARAMCD, "QT") & AVAL > 500, ">500 msec", 4
)
# Assign CHGCAx
chgcax_lookup <- exprs(
~PARAMCD, ~condition, ~CHGCAT1, ~CHGCAT1N,
"QT", CHG <= 30, "<= 30 msec", 1,
"QT", CHG > 30 & CHG <= 60, ">30<=60 msec", 2,
"QT", CHG > 60, ">60 msec", 3
~condition, ~CHGCAT1, ~CHGCAT1N,
starts_with(PARAMCD, "QT") & CHG <= 30, "<= 30 msec", 1,
starts_with(PARAMCD, "QT") & CHG > 30 & CHG <= 60, ">30<=60 msec", 2,
starts_with(PARAMCD, "QT") & CHG > 60, ">60 msec", 3
)

# Derivations ----
Expand Down Expand Up @@ -295,13 +295,11 @@ adeg <- adeg %>%
) %>%
# Derive AVALCA1N and AVALCAT1
derive_vars_cat(
definition = avalcax_lookup,
by_vars = exprs(PARAMCD)
definition = avalcax_lookup
) %>%
# Derive CHGCAT1N and CHGCAT1
derive_vars_cat(
definition = chgcax_lookup,
by_vars = exprs(PARAMCD)
definition = chgcax_lookup
) %>%
# Derive PARAM and PARAMN
derive_vars_merged(
Expand Down
7 changes: 3 additions & 4 deletions man/derive_vars_cat.Rd

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

27 changes: 27 additions & 0 deletions man/extend_condition.Rd

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

64 changes: 39 additions & 25 deletions tests/testthat/test-derive_vars_cat.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ test_that("derive_vars_cat Test 1: Basic functionality without by_vars", {
VSTEST == "Height" & AVAL < 160, "<160", 2
)

expect_dfs_equal(base =
derive_vars_cat(
advs,
definition),
compare = expected_result,
keys = c("USUBJID", "VSTEST"))
expect_dfs_equal(
base =
derive_vars_cat(
advs,
definition
),
compare = expected_result,
keys = c("USUBJID", "VSTEST")
)
})

## Test 2: Basic functionality with by_vars ----
Expand All @@ -74,13 +77,16 @@ test_that("derive_vars_cat Test 2: Basic functionality with by_vars", {



expect_dfs_equal(base =
derive_vars_cat(
advs,
definition,
by_vars = exprs(VSTEST)),
compare = expected_result,
keys = c("USUBJID", "VSTEST"))
expect_dfs_equal(
base =
derive_vars_cat(
advs,
definition,
by_vars = exprs(VSTEST)
),
compare = expected_result,
keys = c("USUBJID", "VSTEST")
)
})

## Test 3: Forgot to specify by_vars ----
Expand Down Expand Up @@ -174,9 +180,11 @@ test_that("derive_vars_cat Test 7: Correct behavior when no conditions are met",
"01-701-1118", "Weight", 71.67, NA_character_, NA_real_
)

expect_dfs_equal(base = derive_vars_cat(advs, definition),
compare = expected_result,
keys = c("USUBJID", "VSTEST"))
expect_dfs_equal(
base = derive_vars_cat(advs, definition),
compare = expected_result,
keys = c("USUBJID", "VSTEST")
)
})

## Test 8: Overlapping conditions handled correctly ----
Expand Down Expand Up @@ -213,9 +221,11 @@ test_that("derive_vars_cat Test 8: Overlapping conditions handled correctly", {
"01-701-1118", "Weight", 71.67, NA, NA
)

expect_dfs_equal(base = derive_vars_cat(advs, definition, by_vars = exprs(VSTEST)),
compare = expected_result,
keys = c("USUBJID", "VSTEST"))
expect_dfs_equal(
base = derive_vars_cat(advs, definition, by_vars = exprs(VSTEST)),
compare = expected_result,
keys = c("USUBJID", "VSTEST")
)
})


Expand Down Expand Up @@ -269,9 +279,11 @@ test_that("derive_vars_cat Test 10: Conditions for multiple VSTESTs (Height and
"01-701-1115", "Weight", 78.7, "Weight >= 66.68", 1,
"01-701-1118", "Weight", 71.67, "Weight >= 66.68", 1
)
expect_dfs_equal(base = derive_vars_cat(advs, definition, by_vars = exprs(VSTEST)),
compare = expected_result,
keys = c("USUBJID", "VSTEST"))
expect_dfs_equal(
base = derive_vars_cat(advs, definition, by_vars = exprs(VSTEST)),
compare = expected_result,
keys = c("USUBJID", "VSTEST")
)
})

## Test 11: Adding an extra variable (flag) to the dataset ----
Expand Down Expand Up @@ -306,9 +318,11 @@ test_that("derive_vars_cat Test 11: Adding an extra variable (flag) to the datas
"01-701-1115", "Weight", 78.7, NA, NA, NA,
"01-701-1118", "Weight", 71.67, NA, NA, NA
)
expect_dfs_equal(base = derive_vars_cat(advs, definition, by_vars = exprs(VSTEST)),
compare = expected_result,
keys = c("USUBJID", "VSTEST"))
expect_dfs_equal(
base = derive_vars_cat(advs, definition, by_vars = exprs(VSTEST)),
compare = expected_result,
keys = c("USUBJID", "VSTEST")
)
})

## Test 12: Wrong input for by_vars ----
Expand Down
Empty file added vignettes/.build.timestamp
Empty file.

0 comments on commit ab4390b

Please sign in to comment.