Skip to content

Commit

Permalink
Merge branch 'main' into 2142_derive_summary_records_get_summary_reco…
Browse files Browse the repository at this point in the history
…rds_mods
  • Loading branch information
zdz2101 authored Oct 24, 2023
2 parents 0e6ec6c + 1ebc258 commit 70836b5
Show file tree
Hide file tree
Showing 20 changed files with 172 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/templates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
pull_request:
branches:
- main
- devel
- patch

jobs:
templates:
Expand Down
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ were enhanced such that more than one summary variable can be derived, e.g.,

## Various

- Website now has button/links to Slack channel and GitHub Issues (#2127)

# admiral 0.12.3

- Fixed a bug in `derive_var_dthcaus()` where if a subject has observations in
more than one of the sources, the one from the last source was selected
regardless of the date. Now the function works as described in its
documentation. (#2154)

# admiral 0.12.2

- A unit test for `derive_param_computed()` was modified in anticipation of major user-facing changes to R version 4.4 (#2147)
Expand Down
6 changes: 3 additions & 3 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
#' Note: Variables `SOC`, `TERM`, `Grade 1`, `Grade 2`,`Grade 3`,`Grade 4`,`Grade 5`, `Definition`
#' are from the source document on NCI-CTC website defining the grading criteria.
#' [**Common Terminology Criteria for Adverse Events (CTCAE)v4.0**](https://ctep.cancer.gov/protocoldevelopment/electronic_applications/ctc.htm#ctc_40)
#' From these variables only 'TERM' is used in the {admiral} code, the rest are for information and
#' From these variables only 'TERM' is used in the `{admiral}` code, the rest are for information and
#' traceability only.
#'
#'
Expand Down Expand Up @@ -124,7 +124,7 @@
#' Note: Variables `SOC`, `TERM`, `Grade 1`, `Grade 2`,`Grade 3`,`Grade 4`,`Grade 5`, `Definition`
#' are from the source document on NCI-CTC website defining the grading criteria.
#' [**Common Terminology Criteria for Adverse Events (CTCAE)v5.0**](https://ctep.cancer.gov/protocoldevelopment/electronic_applications/ctc.htm#ctc_50)
#' From these variables only 'TERM' is used in the {admiral} code, the rest are for information and
#' From these variables only 'TERM' is used in the `{admiral}` code, the rest are for information and
#' traceability only.
#'
#'
Expand Down Expand Up @@ -162,7 +162,7 @@
#' Note: Variables `SOC`, `TERM`, `SUBGROUP`, `Grade 1`, `Grade 2`,`Grade 3`,`Grade 4`,`Grade 5`, `Definition`
#' are from the source document on DAIDS website defining the grading criteria.
#' [Division of AIDS (DAIDS) Table for Grading the Severity of Adult and Pediatric Adverse Events
#' From these variables only 'TERM' is used in the {admiral} code, the rest are for information and
#' From these variables only 'TERM' is used in the `{admiral}` code, the rest are for information and
#' traceability only.
#'
#'
Expand Down
8 changes: 5 additions & 3 deletions R/derive_date_vars.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@
#' `"23:59:59"`. Specifying date variables makes sense only if the date is
#' imputed. If only time is imputed, date variables do not affect the result.

#' @param preserve Preserve day if month is missing and day is present
#' @param preserve Preserve lower level date/time part when higher order part
#' is missing, e.g. preserve day if month is missing or
#' preserve minute when hour is missing.
#'
#' For example `"2019---07"` would return `"2019-06-07` if `preserve = TRUE`
#' (and `date_imputation = "mid"`).
Expand Down Expand Up @@ -1248,7 +1250,7 @@ compute_tmf <- function(dtc,
#' The date can be imputed (see `date_imputation` argument)
#' and the date imputation flag ('`--DTF'`) can be added.
#'
#' In {admiral} we don't allow users to pick any single part of the date/time to
#' In `{admiral}` we don't allow users to pick any single part of the date/time to
#' impute, we only enable to impute up to a highest level, i.e. you couldn't
#' choose to say impute months, but not days.
#'
Expand Down Expand Up @@ -1456,7 +1458,7 @@ derive_vars_dt <- function(dataset, # nolint: cyclocomp_linter
#' The date and time can be imputed (see `date_imputation`/`time_imputation` arguments)
#' and the date/time imputation flag (`'--DTF'`, `'--TMF'`) can be added.
#'
#' In {admiral} we don't allow users to pick any single part of the date/time to
#' In `{admiral}` we don't allow users to pick any single part of the date/time to
#' impute, we only enable to impute up to a highest level, i.e. you couldn't
#' choose to say impute months, but not days.
#'
Expand Down
4 changes: 2 additions & 2 deletions R/derive_var_dthcaus.R
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ derive_var_dthcaus <- function(dataset,

# process each source
add_data <- vector("list", length(sources))
tmp_source_nr <- get_new_tmp_var(dataset)
tmp_date <- get_new_tmp_var(dataset)
for (ii in seq_along(sources)) {
source_dataset_name <- sources[[ii]]$dataset_name
source_dataset <- source_datasets[[source_dataset_name]]
Expand All @@ -183,8 +185,6 @@ derive_var_dthcaus <- function(dataset,
)

# if several death records, use the first/last according to 'mode'
tmp_source_nr <- get_new_tmp_var(dataset)
tmp_date <- get_new_tmp_var(dataset)
add_data[[ii]] <- add_data[[ii]] %>%
filter_extreme(
order = exprs(!!date_var, !!!sources[[ii]]$order),
Expand Down
2 changes: 1 addition & 1 deletion R/derive_vars_dtm_to_tm.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' @details
#' The names of the newly added variables are automatically set by replacing the
#' `--DTM` suffix of the `source_vars` with `--TM`. The `--TM` variables are created
#' using the {hms} package.
#' using the `{hms}` package.
#'
#' @return
#' A data frame containing the input dataset with the corresponding time
Expand Down
2 changes: 1 addition & 1 deletion R/duplicates.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#'
#'
#' @details
#' Many {admiral} function check that the input dataset contains only one record
#' Many `{admiral}` function check that the input dataset contains only one record
#' per `by_vars` group and throw an error otherwise. The `get_duplicates_dataset()`
#' function allows one to retrieve the duplicate records that lead to an error.
#'
Expand Down
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@ to develop ADaM datasets in R.

## Installation

The package is available from CRAN and can be installed by running `install.packages("admiral")`.

To install the latest development version of the package directly from GitHub use the following code:
The package is available from CRAN and can be installed with

```r
if (!requireNamespace("remotes", quietly = TRUE)) {
install.packages("remotes")
}
install.packages("admiral")
```

remotes::install_github("pharmaverse/pharmaversesdtm") # This is a required dependency of {admiral}
remotes::install_github("pharmaverse/admiraldev") # This is a required dependency of {admiral}
remotes::install_github("pharmaverse/admiral")
To install the development version of the package from GitHub run

```r
# install.packages("devtools")
devtools::install_github("pharmaverse/admiral")
```

## Release Schedule
Expand Down
10 changes: 9 additions & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ reference:
navbar:
structure:
left: [getstarted, reference, articles, community, news]
right: [search, slack, newissue, github]
components:
getstarted:
text: Get Started
Expand Down Expand Up @@ -199,5 +200,12 @@ navbar:
href: articles/lab_grading.html
- text: Hy's Law Implementation
href: articles/hys_law.html

slack:
icon: fa-slack
href: https://app.slack.com/client/T028PB489D3/C02M8KN8269
aria-label: Slack
newissue:
icon: fa-bug
href: https://github.com/pharmaverse/admiral/issues/new/choose
aria-label: New Issue

2 changes: 1 addition & 1 deletion man/atoxgr_criteria_ctcv4.Rd

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

2 changes: 1 addition & 1 deletion man/atoxgr_criteria_ctcv5.Rd

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

2 changes: 1 addition & 1 deletion man/atoxgr_criteria_daids.Rd

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

4 changes: 3 additions & 1 deletion man/convert_date_to_dtm.Rd

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

4 changes: 3 additions & 1 deletion man/convert_dtc_to_dtm.Rd

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

2 changes: 1 addition & 1 deletion man/derive_vars_dt.Rd

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

6 changes: 4 additions & 2 deletions man/derive_vars_dtm.Rd

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

2 changes: 1 addition & 1 deletion man/derive_vars_dtm_to_tm.Rd

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

2 changes: 1 addition & 1 deletion man/get_duplicates_dataset.Rd

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

4 changes: 3 additions & 1 deletion man/impute_dtc_dtm.Rd

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

116 changes: 114 additions & 2 deletions tests/testthat/test-derive_var_dthcaus.R
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,8 @@ test_that("derive_var_dthcaus Test 8: `dataset` is sorted using the `order` para
expect_dfs_equal(expected_output, actual_output, keys = "USUBJID")
})

## Test 9: returns a error when traceability_vars is used ----
test_that("derive_var_dthcaus Test 9: returns a error when traceability_vars is used", {
## Test 9: returns a warning when traceability_vars is used ----
test_that("derive_var_dthcaus Test 9: returns a warning when traceability_vars is used", {
ae <- tibble::tribble(
~STUDYID, ~USUBJID, ~AESEQ, ~AEDECOD, ~AEOUT, ~AEDTHDTC,
"TEST01", "PAT01", 12, "SUDDEN DEATH", "FATAL", "2021-04-04"
Expand All @@ -437,3 +437,115 @@ test_that("derive_var_dthcaus Test 9: returns a error when traceability_vars is
class = "lifecycle_error_deprecated"
)
})

## Test 10: multiple observations from different sources ----
test_that("derive_var_dthcaus Test 10: multiple observations from different sources", {
expected <- tibble::tribble(
~STUDYID, ~USUBJID, ~DTHCAUS,
"TEST01", "PAT01", "SUDDEN DEATH",
"TEST01", "PAT02", NA_character_,
"TEST01", "PAT03", "DEATH DUE TO progression of disease"
)

adsl <- select(expected, -DTHCAUS)

ae <- tibble::tribble(
~STUDYID, ~USUBJID, ~AESEQ, ~AEDECOD, ~AEOUT, ~AEDTHDTC,
"TEST01", "PAT01", 12, "SUDDEN DEATH", "FATAL", "2021-04-04"
) %>%
mutate(
AEDTHDT = ymd(AEDTHDTC)
)

ds <- tibble::tribble(
~STUDYID, ~USUBJID, ~DSSEQ, ~DSDECOD, ~DSTERM, ~DSSTDTC,
"TEST01", "PAT01", 4, "DEATH", "DEATH DUE TO progression of disease", "2021-04-05",
"TEST01", "PAT02", 1, "INFORMED CONSENT OBTAINED", "INFORMED CONSENT OBTAINED", "2021-04-02",
"TEST01", "PAT02", 2, "RANDOMIZATION", "RANDOMIZATION", "2021-04-11",
"TEST01", "PAT02", 3, "COMPLETED", "PROTOCOL COMPLETED", "2021-12-01",
"TEST01", "PAT03", 1, "DEATH", "DEATH DUE TO progression of disease", "2021-04-07",
"TEST01", "PAT03", 2, "RANDOMIZATION", "RANDOMIZATION", "2021-04-11",
"TEST01", "PAT03", 3, "COMPLETED", "PROTOCOL COMPLETED", "2021-12-01"
)

# Derive `DTHCAUS` only - for on-study deaths only
src_ae <- dthcaus_source(
dataset_name = "ae",
filter = AEOUT == "FATAL",
date = convert_dtc_to_dt(AEDTHDTC),
mode = "first",
dthcaus = AEDECOD
)

src_ds <- dthcaus_source(
dataset_name = "ds",
filter = DSDECOD == "DEATH" & grepl("DEATH DUE TO", DSTERM),
date = convert_dtc_to_dt(DSSTDTC),
mode = "first",
dthcaus = DSTERM
)
actual <- adsl %>%
derive_var_dthcaus(src_ae, src_ds, source_datasets = list(ae = ae, ds = ds))

expect_dfs_equal(
base = expected,
compare = actual,
keys = c("USUBJID")
)
})

## Test 11: multiple observations from different sources with same date ----
test_that("derive_var_dthcaus Test 11: multiple observations with same date", {
expected <- tibble::tribble(
~STUDYID, ~USUBJID, ~DTHCAUS,
"TEST01", "PAT01", "SUDDEN DEATH",
"TEST01", "PAT02", NA_character_,
"TEST01", "PAT03", "DEATH DUE TO progression of disease"
)

adsl <- select(expected, -DTHCAUS)

ae <- tibble::tribble(
~STUDYID, ~USUBJID, ~AESEQ, ~AEDECOD, ~AEOUT, ~AEDTHDTC,
"TEST01", "PAT01", 12, "SUDDEN DEATH", "FATAL", "2021-04-05"
) %>%
mutate(
AEDTHDT = ymd(AEDTHDTC)
)

ds <- tibble::tribble(
~STUDYID, ~USUBJID, ~DSSEQ, ~DSDECOD, ~DSTERM, ~DSSTDTC,
"TEST01", "PAT01", 4, "DEATH", "DEATH DUE TO progression of disease", "2021-04-05",
"TEST01", "PAT02", 1, "INFORMED CONSENT OBTAINED", "INFORMED CONSENT OBTAINED", "2021-04-02",
"TEST01", "PAT02", 2, "RANDOMIZATION", "RANDOMIZATION", "2021-04-11",
"TEST01", "PAT02", 3, "COMPLETED", "PROTOCOL COMPLETED", "2021-12-01",
"TEST01", "PAT03", 1, "DEATH", "DEATH DUE TO progression of disease", "2021-04-07",
"TEST01", "PAT03", 2, "RANDOMIZATION", "RANDOMIZATION", "2021-04-11",
"TEST01", "PAT03", 3, "COMPLETED", "PROTOCOL COMPLETED", "2021-12-01"
)

# Derive `DTHCAUS` only - for on-study deaths only
src_ae <- dthcaus_source(
dataset_name = "ae",
filter = AEOUT == "FATAL",
date = convert_dtc_to_dt(AEDTHDTC),
mode = "first",
dthcaus = AEDECOD
)

src_ds <- dthcaus_source(
dataset_name = "ds",
filter = DSDECOD == "DEATH" & grepl("DEATH DUE TO", DSTERM),
date = convert_dtc_to_dt(DSSTDTC),
mode = "first",
dthcaus = DSTERM
)
actual <- adsl %>%
derive_var_dthcaus(src_ae, src_ds, source_datasets = list(ae = ae, ds = ds))

expect_dfs_equal(
base = expected,
compare = actual,
keys = c("USUBJID")
)
})

0 comments on commit 70836b5

Please sign in to comment.