Skip to content

Commit

Permalink
Merge pull request #254 from pharmaverse/253-feature-request-deprecat…
Browse files Browse the repository at this point in the history
…esupersede-derive_vars_crit

253 feature request deprecatesupersede derive vars crit
  • Loading branch information
ahasoplakus authored Jan 28, 2025
2 parents 5bf3c69 + 959f2d2 commit 187f152
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 116 deletions.
1 change: 1 addition & 0 deletions .lycheeignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ https://cran.r-project.org/package=admiralvaccine
https://pharmaverse.github.io/admiralvaccine/reference
https://pharmaverse.github.io/admiralvaccine/articles
https://github.com/pharmaverse/admiralvaccine/blob/*
https://www.fda.gov/media/112581/download
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: admiralvaccine
Title: Vaccine Extension Package for ADaM in 'R' Asset Library
Version: 0.3.0
Version: 0.4.0
Authors@R: c(
person("Sukalpo", "Saha", email = "[email protected]", role = c("aut", "cre")),
person("Arjun", "Rubalingam", email = "[email protected]", role = "aut"),
Expand Down Expand Up @@ -83,8 +83,9 @@ Suggests:
metatools
VignetteBuilder:
knitr
Config/testthat/edition: 3
Encoding: UTF-8
Language: en-US
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# admiralvaccine 0.4.0

## Breaking Changes

- Function `derive_vars_crit()` has been deprecated. Please use `admiral::derive_vars_crit_flag()` instead. (#253)

# admiralvaccine 0.3.0

## Updates related to CBER requirements for eDiary data
Expand Down
18 changes: 14 additions & 4 deletions R/derive_vars_crit.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#'
#' @description
#' Derive analysis criterion evaluation result variable, paired with character
#' and numeric flags.
#' This function allows also the derivation of a CRIT like variable with a
#' different name (ex: `ANL01FL`), without generating additional numeric (ex: `ANL01FN`)
#' and character label (ex: `ANL01`) variables.
#'
#' `r lifecycle::badge("deprecated")`
#'
#' This function is *deprecated*, please use `admiral::derive_vars_crit_flag()` instead.
#'
#' @param dataset Input dataset
#'
Expand Down Expand Up @@ -94,6 +94,16 @@
#' )
#'
derive_vars_crit <- function(dataset, prefix, crit_label, condition, criterion) {
deprecate_warn(
when = "0.4.0",
what = "derive_vars_crit()",
with = "admiral::derive_vars_crit_flag()",
details = c(
x = "This message will turn into a error at the beginning of 2026.",
i = "See admiral's deprecation guidance:
https://pharmaverse.github.io/admiraldev/dev/articles/programming_strategy.html#deprecation"
)
)
condition <- assert_filter_cond(enquo(condition))
criterion <- assert_filter_cond(enquo(criterion))

Expand Down
18 changes: 12 additions & 6 deletions inst/templates/ad_adis.R
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,19 @@ adis <- restrict_derivation(adis,


# STEP 9 Derivation of CRITyFL and CRITyFN ----
adis <- derive_vars_crit(
adis <- restrict_derivation(
dataset = adis,
prefix = "CRIT1",
crit_label = "Titer >= ISLLOQ",
condition = !is.na(AVAL) & !is.na(ISLLOQ),
criterion = AVAL >= ISLLOQ
)
derivation = derive_vars_crit_flag,
args = params(
crit_nr = 1,
condition = AVAL >= ISLLOQ,
description = "Titer >= ISLLOQ",
values_yn = TRUE,
create_numeric_flag = TRUE
),
filter = !is.na(AVAL)
) %>%
arrange(STUDYID, USUBJID, DERIVED, ISSEQ)


# STEP 10 Derivation of TRTP/A treatment variables ----
Expand Down
8 changes: 4 additions & 4 deletions man/derive_vars_crit.Rd

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

173 changes: 84 additions & 89 deletions tests/testthat/test-derive_vars_crit.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
## Test 1: Derive CRIT1 variables
## Test 1: deprecation message if function is called

test_that("derive_vars_crit Test 1: Derive CRIT1 variables", {
# input data
test_that("derive_vars_crit() Test #: deprecation message if function is called", {
input <- tibble::tribble(
~USUBJID, ~AVISITN, ~PARAMCD, ~AVAL, ~ISLLOQ,
"999999-000001", 10, "J0033VN", 2, 4,
Expand Down Expand Up @@ -30,36 +29,26 @@ test_that("derive_vars_crit Test 1: Derive CRIT1 variables", {
!is.na(AVAL) & !is.na(ISLLOQ) & AVAL < ISLLOQ ~ "N",
TRUE ~ as.character(NA)
),
CRIT1FN = if_else(CRIT1FL == "Y", 1, 0),
CRIT1 = if_else(!is.na(CRIT1FL), "Titer >= ISLLOQ", as.character(NA))
CRIT1 = if_else(!is.na(CRIT1FL), "Titer >= ISLLOQ", as.character(NA)),
CRIT1FN = if_else(CRIT1FL == "Y", 1, 0)
)


# actual dataset
actual <- derive_vars_crit(
dataset = input,
prefix = "CRIT1",
crit_label = "Titer >= ISLLOQ",
condition = !is.na(AVAL) & !is.na(ISLLOQ),
criterion = AVAL >= ISLLOQ
)

expect_dfs_equal(actual,
expected,
keys = c(
"USUBJID", "AVISITN", "PARAMCD", "AVAL", "ISLLOQ", "CRIT1FL",
"CRIT1FN", "CRIT1"
)
expect_warning(
derive_vars_crit(
dataset = input,
prefix = "CRIT1",
crit_label = "Titer >= ISLLOQ",
condition = !is.na(AVAL) & !is.na(ISLLOQ),
criterion = AVAL >= ISLLOQ
),
class = "lifecycle_warning_deprecated"
)
})


## Test 2: Derive CRIT1 variables


## Test 2: Derive CRIT1 variables when AVAL is missing

test_that("derive_vars_crit Test 2: Derive CRIT1 variables
when AVAL is missing", {
test_that("derive_vars_crit Test 2: Derive CRIT1 variables", {
# input data
input <- tibble::tribble(
~USUBJID, ~AVISITN, ~PARAMCD, ~AVAL, ~ISLLOQ,
Expand All @@ -71,14 +60,14 @@ test_that("derive_vars_crit Test 2: Derive CRIT1 variables
"999999-000001", 30, "I0019NT", 567, 6,
"999999-000001", 30, "M0019LN", 659, 4,
"999999-000001", 30, "R0003MA", 250, 6,
"999999-000002", 10, "J0033VN", NA, 4,
"999999-000002", 10, "I0019NT", NA, 6,
"999999-000002", 10, "M0019LN", NA, 4,
"999999-000002", 10, "R0003MA", NA, 6,
"999999-000002", 30, "J0033VN", NA, 4,
"999999-000002", 30, "I0019NT", NA, 6,
"999999-000002", 30, "M0019LN", NA, 4,
"999999-000002", 30, "R0003MA", NA, 6
"999999-000002", 10, "J0033VN", 2, 4,
"999999-000002", 10, "I0019NT", 7, 6,
"999999-000002", 10, "M0019LN", 5, 4,
"999999-000002", 10, "R0003MA", 3, 6,
"999999-000002", 30, "J0033VN", 55, 4,
"999999-000002", 30, "I0019NT", 89, 6,
"999999-000002", 30, "M0019LN", 990, 4,
"999999-000002", 30, "R0003MA", 340, 6
)

# expected dataset
Expand All @@ -89,18 +78,21 @@ test_that("derive_vars_crit Test 2: Derive CRIT1 variables
!is.na(AVAL) & !is.na(ISLLOQ) & AVAL < ISLLOQ ~ "N",
TRUE ~ as.character(NA)
),
CRIT1FN = if_else(CRIT1FL == "Y", 1, 0),
CRIT1 = if_else(!is.na(CRIT1FL), "Titer >= ISLLOQ", as.character(NA))
CRIT1 = if_else(!is.na(CRIT1FL), "Titer >= ISLLOQ", as.character(NA)),
CRIT1FN = if_else(CRIT1FL == "Y", 1, 0)
)


# actual dataset
actual <- derive_vars_crit(
dataset = input,
prefix = "CRIT1",
crit_label = "Titer >= ISLLOQ",
condition = !is.na(AVAL) & !is.na(ISLLOQ),
criterion = AVAL >= ISLLOQ
actual <- admiraldev::suppress_warning(
derive_vars_crit(
dataset = input,
prefix = "CRIT1",
crit_label = "Titer >= ISLLOQ",
condition = !is.na(AVAL) & !is.na(ISLLOQ),
criterion = AVAL >= ISLLOQ
),
regexpr = "was deprecated"
)

expect_dfs_equal(actual,
Expand All @@ -112,64 +104,67 @@ test_that("derive_vars_crit Test 2: Derive CRIT1 variables
)
})

## Test 3: Derive CRIT1 variables when AVAL is missing



## Test 3: Try to apply different vars name and missing ISLLOQ or AVAL

test_that("derive_vars_crit Test 3: Try to apply different vars name and
missing ISLLOQ or AVAL", {
test_that("derive_vars_crit Test 3: Derive CRIT1 variables when AVAL is missing", {
# input data
input <- tibble::tribble(
~USUBJID, ~AVISITN, ~PARAMCD, ~AVAL, ~ISLLOQ,
"999999-000001", 10, "J0033VN", NA, NA,
"999999-000001", 10, "I0019NT", NA, 6,
"999999-000001", 10, "M0019LN", NA, 4,
"999999-000001", 10, "R0003MA", NA, 6,
"999999-000001", 30, "J0033VN", NA, NA,
"999999-000001", 30, "I0019NT", NA, 6,
"999999-000001", 30, "M0019LN", NA, 4,
"999999-000001", 30, "R0003MA", NA, 6,
"999999-000002", 10, "J0033VN", 2, NA,
"999999-000002", 10, "I0019NT", 7, 6,
"999999-000002", 10, "M0019LN", 5, 4,
"999999-000002", 10, "R0003MA", 3, 6,
"999999-000002", 30, "J0033VN", 55, NA,
"999999-000002", 30, "I0019NT", 89, 6,
"999999-000002", 30, "M0019LN", 990, 4,
"999999-000002", 30, "R0003MA", 340, 6
"999999-000001", 10, "J0033VN", 2, 4,
"999999-000001", 10, "I0019NT", 3, 6,
"999999-000001", 10, "M0019LN", 4, 4,
"999999-000001", 10, "R0003MA", 3, 6,
"999999-000001", 30, "J0033VN", 60, 4,
"999999-000001", 30, "I0019NT", 567, 6,
"999999-000001", 30, "M0019LN", 659, 4,
"999999-000001", 30, "R0003MA", 250, 6,
"999999-000002", 10, "J0033VN", NA, 4,
"999999-000002", 10, "I0019NT", NA, 6,
"999999-000002", 10, "M0019LN", NA, 4,
"999999-000002", 10, "R0003MA", NA, 6,
"999999-000002", 30, "J0033VN", NA, 4,
"999999-000002", 30, "I0019NT", NA, 6,
"999999-000002", 30, "M0019LN", NA, 4,
"999999-000002", 30, "R0003MA", NA, 6
)

# expected dataset
expected <- input %>%
mutate(
ANL01FL = case_when(
CRIT1FL = case_when(
!is.na(AVAL) & !is.na(ISLLOQ) & AVAL >= ISLLOQ ~ "Y",
!is.na(AVAL) & !is.na(ISLLOQ) & AVAL < ISLLOQ ~ "N",
TRUE ~ as.character(NA)
)
),
CRIT1 = if_else(!is.na(CRIT1FL), "Titer >= ISLLOQ", as.character(NA)),
CRIT1FN = if_else(CRIT1FL == "Y", 1, 0)
)


# actual dataset
actual <- derive_vars_crit(
dataset = input,
prefix = "ANL01",
crit_label = "Titer >= ISLLOQ",
condition = !is.na(AVAL) & !is.na(ISLLOQ),
criterion = AVAL >= ISLLOQ
actual <- admiraldev::suppress_warning(
derive_vars_crit(
dataset = input,
prefix = "CRIT1",
crit_label = "Titer >= ISLLOQ",
condition = !is.na(AVAL) & !is.na(ISLLOQ),
criterion = AVAL >= ISLLOQ
),
regexpr = "was deprecated"
)

expect_dfs_equal(actual,
expected,
keys = c("USUBJID", "AVISITN", "PARAMCD", "AVAL", "ISLLOQ", "ANL01FL")
keys = c(
"USUBJID", "AVISITN", "PARAMCD", "AVAL", "ISLLOQ", "CRIT1FL",
"CRIT1FN", "CRIT1"
)
)
})

## Test 4: Complicated selections and missing values for AVAL and ISLLOQ

test_that("derive_vars_crit Test 4: Complicated selections and missing values
for AVAL and ISLLOQ", {
test_that("derive_vars_crit Test 4: Complicated selections and missing values for AVAL and
ISLLOQ", {
# input data
input <- tibble::tribble(
~USUBJID, ~AVISITN, ~PARAMCD, ~AVAL, ~ISLLOQ, ~BASE,
Expand All @@ -194,23 +189,23 @@ test_that("derive_vars_crit Test 4: Complicated selections and missing values
# expected dataset
expected <- input %>%
mutate(
CRIT1FL = case_when(
!is.na(AVAL) & !is.na(ISLLOQ) & is.na(BASE) & AVAL >= ISLLOQ & AVAL >= 2 * BASE ~ "Y",
!is.na(AVAL) & !is.na(ISLLOQ) & is.na(BASE) & AVAL < ISLLOQ & AVAL >= 2 * BASE ~ "N",
TRUE ~ as.character(NA)
CRIT1FL = if_else(
AVAL >= ISLLOQ & AVAL >= 2 * BASE, "Y", "N"
),
CRIT1FN = if_else(CRIT1FL == "Y", 1, 0),
CRIT1 = if_else(!is.na(CRIT1FL), "Titer >= ISLLOQ", as.character(NA))
CRIT1 = if_else(!is.na(CRIT1FL), "Titer >= ISLLOQ and Titer >= 2*BASE", as.character(NA)),
CRIT1FN = if_else(CRIT1FL == "Y", 1, 0)
)


# actual dataset
actual <- derive_vars_crit(
dataset = input,
prefix = "CRIT1",
crit_label = "Titer >= ISLLOQ and Titer >= 2*BASE",
condition = !is.na(AVAL) & !is.na(ISLLOQ) & is.na(BASE),
criterion = AVAL >= ISLLOQ & AVAL >= 2 * BASE
actual <- admiraldev::suppress_warning(
derive_vars_crit(
dataset = input,
prefix = "CRIT1",
crit_label = "Titer >= ISLLOQ and Titer >= 2*BASE",
condition = !is.na(AVAL),
criterion = AVAL >= ISLLOQ & AVAL >= 2 * BASE
),
regexpr = "was deprecated"
)

expect_dfs_equal(actual,
Expand Down
Loading

0 comments on commit 187f152

Please sign in to comment.