Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
bms63 authored Dec 20, 2024
2 parents be9c591 + a92dd68 commit 44f913a
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 30 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: admiral
Title: ADaM in R Asset Library
Version: 1.1.1.9041
Version: 1.1.1.9045
Authors@R: c(
person("Ben", "Straub", , "[email protected]", role = c("aut", "cre")),
person("Stefan", "Bundfuss", role = "aut",
Expand Down
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
12 changes: 5 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,8 @@ derive_vars_crit_flag <- function(dataset,

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

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

if (create_numeric_flag) {
new_critflnvar <- paste0("CRIT", as.character(crit_nr), "FLN")
new_critfnvar <- paste0("CRIT", as.character(crit_nr), "FN")
dataset <- dataset %>% mutate(
!!new_critflnvar := yn_to_numeric(!!sym(new_critflvar))
!!new_critfnvar := as.integer(yn_to_numeric(!!sym(new_critflvar)))
)
}
dataset
Expand Down
3 changes: 2 additions & 1 deletion R/derive_vars_transposed.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ derive_vars_transposed <- function(dataset,
optional = TRUE
)

dataset_merge <- filter_if(dataset_merge, filter)

# check for duplicates in dataset_merge as these will create list columns,
# which is not acceptable for ADaM datasets
signal_duplicate_records(
Expand All @@ -134,7 +136,6 @@ derive_vars_transposed <- function(dataset,
)

dataset_transposed <- dataset_merge %>%
filter_if(filter) %>%
pivot_wider(
names_from = !!key_var,
values_from = !!value_var,
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.

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/compute_scale.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
! Argument `target_range` is missing with no default and `source_range` is not missing.
i Either both or neither arguments should be specified.

---
# compute_scale Test 7: error if target_range is supplied, but not source_range

Code
compute_scale(input, target_range = c(0, 100), min_n = 2)
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/_snaps/derive_var_trtemfl.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,12 @@
! `intensity` argument was specified but not `initial_intensity`
Either both or none of them must be specified.

# derive_var_trtemfl Test 11: error if `group_var` without `subject_keys`

Code
derive_var_trtemfl(adae, group_var = AEGRPID, subject_keys = NULL)
Condition
Error in `derive_var_trtemfl()`:
! `group_var` argument was specified but not `subject_keys`
`subject_keys` argument must be provided when `group_var` is specified.

14 changes: 13 additions & 1 deletion tests/testthat/test-derive_var_trtemfl.R
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ test_that("derive_var_trtemfl Test 9: error if `intensity` without `initial_inte
})

## Test 10: warning if both `initial_intensity` and `group_var` are specified ----
test_that("derive_var_trtemfl Test 9: error if `intensity` without `initial_intensity`", {
test_that("derive_var_trtemfl Test 10: error if `intensity` without `initial_intensity`", {
expect_warning(
derive_var_trtemfl(
adae2,
Expand All @@ -204,3 +204,15 @@ test_that("derive_var_trtemfl Test 9: error if `intensity` without `initial_inte
"`initial_intensity` argument is ignored when `group_var` is specified"
)
})

## Test 11: error if `group_var` are specified without `subject_keys` ----
test_that("derive_var_trtemfl Test 11: error if `group_var` without `subject_keys`", {
expect_snapshot(
derive_var_trtemfl(
adae,
group_var = AEGRPID,
subject_keys = NULL
),
error = TRUE
)
})
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, ~CRIT1FLN, ~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, ~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", 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
9 changes: 9 additions & 0 deletions tests/testthat/test-derive_vars_transposed.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ test_that("derive_vars_transposed Test 2: filtering the merge dataset works", {
"STUDY01", "P02", 31, 3,
"STUDY01", "P03", 42, NA
)

dataset_merge <- tibble::tribble(
~STUDYID, ~USUBJID, ~TESTCD, ~VALUE,
"STUDY01", "P01", "T01", 31,
"STUDY01", "P01", "T02", 5,
"STUDY01", "P02", "T01", 3,
"STUDY01", "P01", "T02", 9
)

actual_output <- derive_vars_transposed(
dataset,
dataset_merge,
Expand Down
10 changes: 5 additions & 5 deletions vignettes/bds_finding.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ otherwise specified.*
* [Assign Treatment (`TRTA`, `TRTP`)](#treatment)
* [Assign `ASEQ`](#aseq)
* [Derive Categorization Variables (`AVALCATy`)](#cat)
* [Derive Criterion Variables (`CRITy`, `CRITyFL`, `CRITyFLN`)](#crit_vars)
* [Derive Criterion Variables (`CRITy`, `CRITyFL`, `CRITyFN`)](#crit_vars)
* [Add ADSL variables](#adsl_vars)
* [Derive New Rows](#additional)
* [Add Labels and Attributes](#attributes)
Expand Down Expand Up @@ -879,9 +879,9 @@ dataset_vignette(
)
```

## Derive Criterion Variables (`CRITy`, `CRITyFL`, `CRITyFLN`) {#crit_vars}
## Derive Criterion Variables (`CRITy`, `CRITyFL`, `CRITyFN`) {#crit_vars}

For deriving criterion variables (`CRITy`, `CRITyFL`, `CRITyFLN`) `{admiral}`
For deriving criterion variables (`CRITy`, `CRITyFL`, `CRITyFN`) `{admiral}`
provides `derive_vars_crit_flag()`. It ensures that they are derived in an
ADaM-compliant way (see documentation of the function for details).

Expand Down Expand Up @@ -921,7 +921,7 @@ advs <- advs %>%
```{r, eval=TRUE, echo=FALSE}
dataset_vignette(
arrange(advs, USUBJID, AVISITN, ATPTN, PARAMCD),
display_vars = exprs(USUBJID, PARAMCD, AVAL, CHG, CRIT1, CRIT1FL, CRIT1FLN),
display_vars = exprs(USUBJID, PARAMCD, AVAL, CHG, CRIT1, CRIT1FL, CRIT1FN),
filter = PARAMCD %in% c("DIABP", "SYSBP")
)
```
Expand All @@ -946,7 +946,7 @@ advs <- advs %>%
```{r, eval=TRUE, echo=FALSE}
dataset_vignette(
arrange(advs, USUBJID, AVISITN, ATPTN),
display_vars = exprs(USUBJID, PARAMCD, AVAL, CHG, CRIT2, CRIT2FL, CRIT2FLN),
display_vars = exprs(USUBJID, PARAMCD, AVAL, CHG, CRIT2, CRIT2FL, CRIT2FN),
filter = PARAMCD == "SYSBP"
)
```
Expand Down

0 comments on commit 44f913a

Please sign in to comment.