Skip to content

Commit

Permalink
Release {admiral} v0.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Neitmann authored Jul 15, 2022
2 parents 5e87df4 + c1dd616 commit dfb6489
Show file tree
Hide file tree
Showing 21 changed files with 230 additions and 78 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/R-CMD-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ on:
push:
branches:
- main
- patch
- devel
pull_request:
branches:
- main
- patch
- devel

name: R-CMD-check
Expand Down Expand Up @@ -65,7 +67,7 @@ jobs:
run: |
options(repos = Sys.getenv("R_REPOS"))
remotes::install_deps(dependencies = TRUE)
ref <- if (Sys.getenv("GITHUB_REF_NAME") == "main") "main" else "devel"
ref <- if (Sys.getenv("GITHUB_REF_NAME") %in% c("main", "patch")) "main" else "devel"
remotes::install_github(
"pharmaverse/admiral.test",
ref = ref,
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ on:
push:
branches:
- main
- patch
- devel
pull_request:
branches:
- main
- patch
- devel

name: Code Coverage ☂
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/lintr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ on:
push:
branches:
- main
- patch
- devel
pull_request:
branches:
- main
- patch
- devel

name: lint
Expand Down Expand Up @@ -50,7 +52,6 @@ jobs:
run: |
if (!requireNamespace("renv", quietly = TRUE)) install.packages("renv")
renv::restore()
renv::install("lintr")
shell: Rscript {0}

- name: Install package
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/man-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ on:
push:
branches:
- main
- patch
- devel
pull_request:
branches:
- main
- patch
- devel
issue_comment:
types: [created]
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/spellcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ on:
push:
branches:
- main
- patch
- devel
pull_request:
branches:
- main
- patch
- devel

concurrency:
Expand Down Expand Up @@ -60,7 +62,7 @@ jobs:
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')
- name: Install spelling 🎓
run: |
if (!requireNamespace("renv", quietly = TRUE)) install.packages("renv")
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ on:
push:
branches:
- main
- patch
- devel
pull_request:
branches:
- main
- patch
- devel

concurrency:
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: admiral
Type: Package
Title: ADaM in R Asset Library
Version: 0.7.0
Version: 0.7.1
Authors@R: c(
person("Thomas", "Neitmann", email = "[email protected]", role = c("aut", "cre")),
person("Stefan", "Bundfuss", role = "aut"),
Expand Down
15 changes: 15 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# admiral 0.7.1

- `derive_vars_last_dose()` no longer fails when a variable renamed in `new_vars` is supplied
to the `dose_date` parameter (#1206)

- `derive_vars_duration()` updated to not display units when there is missing
duration (#1207)

- `derive_param_first_event()` was updated (#1214) such that
- `AVAL` is derived instead of `AVALN` and
- all variables from the source dataset are kept.

- `slice_derivation()` was updated such that it no longer fails if a slice is
empty (#1309)

# admiral 0.7.0

## New Features
Expand Down
32 changes: 21 additions & 11 deletions R/derive_param_first_event.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
#' subjects with event `AVALC` is set to `"Y"`, `AVAL` to `1`, and `ADT` to
#' the first date where the event condition is fulfilled. For all other
#' subjects `AVALC` is set to `"N"`, `AVAL` to `0`, and `ADT` to `NA`.
#' For subjects with event all variables from `dataset_source` are kept. For
#' subjects without event all variables which are in both `dataset_adsl` and
#' `dataset_source` are kept.
#' 1. The variables specified by the `set_values_to` parameter are added to
#' the new observations.
#' 1. The new observations are added to input dataset.
Expand Down Expand Up @@ -169,19 +172,26 @@ derive_param_first_event <- function(dataset,
assert_param_does_not_exist(dataset, quo_get_expr(set_values_to$PARAMCD))

# Create new observations
new_obs <- derive_vars_merged(
select(dataset_adsl, !!!subject_keys),
dataset_add = dataset_source,
filter_add = !!filter_source,
by_vars = subject_keys,
order = vars(!!date_var),
new_vars = vars(ADT = !!date_var),
mode = "first",
check_type = check_type
) %>%
source_vars <- colnames(dataset_source)
adsl_vars <- colnames(dataset_adsl)

events <- dataset_source %>%
filter_if(filter_source) %>%
filter_extreme(
by_vars = subject_keys,
order = vars(!!date_var),
mode = "first",
check_type = check_type
)
noevents <- anti_join(
select(dataset_adsl, intersect(source_vars, adsl_vars)),
select(events, !!!subject_keys)
)
new_obs <- bind_rows(events, noevents) %>%
mutate(
ADT = !!date_var,
AVALC = if_else(!is.na(ADT), "Y", "N"),
AVALN = if_else(!is.na(ADT), 1, 0),
AVAL = if_else(!is.na(ADT), 1, 0),
!!!set_values_to
)

Expand Down
19 changes: 10 additions & 9 deletions R/derive_var_ontrtfl.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@
#' @export
#'
#' @examples
#' library(tibble)
#' library(dplyr)
#' library(lubridate, warn.conflict = FALSE)
#'
#' advs <- tibble::tribble(
#' advs <- tribble(
#' ~USUBJID, ~ADT, ~TRTSDT, ~TRTEDT,
#' "P01", ymd("2020-02-24"), ymd("2020-01-01"), ymd("2020-03-01"),
#' "P02", ymd("2020-01-01"), ymd("2020-01-01"), ymd("2020-03-01"),
Expand All @@ -108,7 +109,7 @@
#' ref_end_date = TRTEDT
#' )
#'
#' advs <- tibble::tribble(
#' advs <- tribble(
#' ~USUBJID, ~ADT, ~TRTSDT, ~TRTEDT,
#' "P01", ymd("2020-07-01"), ymd("2020-01-01"), ymd("2020-03-01"),
#' "P02", ymd("2020-04-30"), ymd("2020-01-01"), ymd("2020-03-01"),
Expand All @@ -122,11 +123,11 @@
#' ref_end_window = 60
#' )
#'
#' advs <- tibble::tribble(
#' ~USUBJID, ~ADTM, ~TRTSDTM, ~TRTEDTM,
#' "P01", ymd("2020-01-02T12:00"), ymd_hm("2020-01-01T12:00"), ymd_hm("2020-03-01T12:00"),
#' "P02", ymd("2020-01-01"), ymd_hm("2020-01-01T12:00"), ymd_hm("2020-03-01T12:00"),
#' "P03", ymd("2019-12-31"), ymd_hm("2020-01-01T12:00"), ymd_hm("2020-03-01T12:00"),
#' advs <- tribble(
#' ~USUBJID, ~ADTM, ~TRTSDTM, ~TRTEDTM,
#' "P01", ymd_hm("2020-01-02T12:00"), ymd_hm("2020-01-01T12:00"), ymd_hm("2020-03-01T12:00"),
#' "P02", ymd("2020-01-01"), ymd_hm("2020-01-01T12:00"), ymd_hm("2020-03-01T12:00"),
#' "P03", ymd("2019-12-31"), ymd_hm("2020-01-01T12:00"), ymd_hm("2020-03-01T12:00"),
#' ) %>%
#' mutate(TPT = c(NA, "PRE", NA))
#' derive_var_ontrtfl(
Expand All @@ -137,7 +138,7 @@
#' filter_pre_timepoint = TPT == "PRE"
#' )
#'
#' advs <- tibble::tribble(
#' advs <- tribble(
#' ~USUBJID, ~ASTDT, ~TRTSDT, ~TRTEDT, ~AENDT,
#' "P01", ymd("2020-03-15"), ymd("2020-01-01"), ymd("2020-03-01"), ymd("2020-12-01"),
#' "P02", ymd("2019-04-30"), ymd("2020-01-01"), ymd("2020-03-01"), ymd("2020-03-15"),
Expand All @@ -153,7 +154,7 @@
#' span_period = "Y"
#' )
#'
#' advs <- tibble::tribble(
#' advs <- tribble(
#' ~USUBJID, ~ASTDT, ~AP01SDT, ~AP01EDT, ~AENDT,
#' "P01", ymd("2020-03-15"), ymd("2020-01-01"), ymd("2020-03-01"), ymd("2020-12-01"),
#' "P02", ymd("2019-04-30"), ymd("2020-01-01"), ymd("2020-03-01"), ymd("2020-03-15"),
Expand Down
13 changes: 10 additions & 3 deletions R/derive_vars_duration.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,15 @@
#' @seealso [compute_duration()]
#'
#' @examples
#' data <- tibble::tribble(
#' library(lubridate)
#' library(tibble)
#'
#' data <- tribble(
#' ~BRTHDT, ~RANDDT,
#' lubridate::ymd("1984-09-06"), lubridate::ymd("2020-02-24")
#' ymd("1984-09-06"), ymd("2020-02-24"),
#' ymd("1985-01-01"), NA,
#' NA, ymd("2021-03-10"),
#' NA, NA
#' )
#'
#' derive_vars_duration(data,
Expand Down Expand Up @@ -143,7 +149,8 @@ derive_vars_duration <- function(dataset,
)

if (!quo_is_null(new_var_unit)) {
dataset <- dataset %>% mutate(!!new_var_unit := toupper(out_unit))
dataset <- dataset %>%
mutate(!!new_var_unit := if_else(is.na(!!new_var), NA_character_, toupper(out_unit)))
}

dataset
Expand Down
45 changes: 33 additions & 12 deletions R/derive_vars_last_dose.R
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
#' Derive Last Dose
#'
#' Add EX source variables from last dose to the input dataset.
#'
#' @param dataset Input dataset.
#' The variables specified by the `by_vars` and `analysis_date` parameters are expected.
#'
#' @param dataset_ex Input EX dataset.
#' The variables specified by the `by_vars`, `dose_date`, `new_vars` parameters,
#' and source variables from `traceability_vars` parameter are expected.
#'
#' @param filter_ex Filtering condition applied to EX dataset.
#' For example, it can be used to filter for valid dose.
#' Defaults to NULL.
#'
#' @param by_vars Variables to join by (created by `dplyr::vars`).
#'
#' @param dose_id Variables to identify unique dose (created by `dplyr::vars`).
#' Defaults to empty `vars()`.
#'
#' @param new_vars Variables to keep from `dataset_ex`, with the option to rename. Can either
#' be variables created by `dplyr::vars` (e.g. `vars(VISIT)`), or named list returned by [`vars()`]
#' (e.g. `vars(LSTEXVIS = VISIT)`). If set to `NULL`, then all variables from `dataset_ex` are
#' kept without renaming.
#' Defaults to `NULL`.
#'
#' @param dose_date The EX dose date variable. A date or date-time object is expected.
#'
#' @param analysis_date The analysis date variable. A date or date-time object is expected.
#'
#' @param single_dose_condition The condition for checking if `dataset_ex` is single dose. An error
#' is issued if the condition is not true. Defaults to `(EXDOSFRQ == "ONCE")`.
#'
#' @param traceability_vars A named list returned by [`vars()`] listing the traceability variables,
#' e.g. `vars(LDOSEDOM = "EX", LDOSESEQ = EXSEQ)`.
#' The left-hand side (names of the list elements) gives the names of the traceability variables
Expand All @@ -29,14 +39,16 @@
#' in the returned dataset.
#' These can be either strings or symbols referring to existing variables.
#'
#' @details All date (date-time) variables can be characters in standard ISO format or
#' @details
#' All date (date-time) variables can be characters in standard ISO format or
#' of date / date-time class.
#' For ISO format, see [`impute_dtc`] - parameter `dtc` for further details.
#' When doing date comparison to identify last dose, date-time imputations are done as follows:
#' * `dose_date`: no date imputation, time imputation to `00:00:00` if time is missing.
#' * `analysis_date`: no date imputation, time imputation to `23:59:59` if time is missing.
#'
#' The last dose records are identified as follows:
#'
#' 1. The `dataset_ex` is filtered using `filter_ex`, if provided.
#' This is useful for, for example, filtering for valid dose only.
#' 2. The datasets `dataset` and `dataset_ex` are joined using `by_vars`.
Expand All @@ -52,9 +64,9 @@
#' `dataset` and returned to the user.
#'
#' This function only works correctly for EX dataset with a structure of single dose per row.
#' If your study EX dataset has multiple doses per row, use `expansion_function_name??` to
#' If your study EX dataset has multiple doses per row, use [`create_single_dose_dataset()`] to
#' transform the EX dataset into single dose per row structure before calling
#' `derive_vars_last_dose`.
#' `derive_vars_last_dose()`.
#'
#' If variables (other than those specified in `by_vars`) exist in both `dataset` and `dataset_ex`,
#' then join cannot be performed properly and an error is issued. To resolve the error, use
Expand Down Expand Up @@ -109,7 +121,7 @@ derive_vars_last_dose <- function(dataset,
dose_id = vars(),
dose_date,
analysis_date,
single_dose_condition = (EXDOSFRQ == "ONCE"),
single_dose_condition = EXDOSFRQ == "ONCE",
new_vars = NULL,
traceability_vars = NULL) {
filter_ex <- assert_filter_cond(enquo(filter_ex), optional = TRUE)
Expand All @@ -121,10 +133,12 @@ derive_vars_last_dose <- function(dataset,
assert_varval_list(new_vars, optional = TRUE, accept_var = TRUE)
assert_varval_list(traceability_vars, optional = TRUE)
assert_data_frame(dataset, quo_c(by_vars, analysis_date))
assert_data_frame(dataset_ex, quo_c(
by_vars, dose_date, new_vars,
get_source_vars(traceability_vars)
))
if (as_name(dose_date) %in% names(new_vars)) {
required_vars <- quo_c(by_vars, new_vars, get_source_vars(traceability_vars))
} else {
required_vars <- quo_c(by_vars, dose_date, new_vars, get_source_vars(traceability_vars))
}
assert_data_frame(dataset_ex, required_vars)

# vars converted to string
by_vars_str <- vars2chr(by_vars)
Expand All @@ -136,15 +150,22 @@ derive_vars_last_dose <- function(dataset,
all()

if (!single_dose_eval) {
stop("Specified single_dose_condition is not satisfied.")
stop("Specified `single_dose_condition` is not satisfied.")
}

# check if doses are unique based on dose_date and dose_id
# check if doses are unique based on `dose_date` and `dose_id`
if (as_name(dose_date) %in% names(new_vars)) {
unique_by <- c(by_vars, new_vars[[as_name(dose_date)]], dose_id)
} else {
unique_by <- c(by_vars, dose_date, dose_id)
}
signal_duplicate_records(
dataset_ex, c(by_vars, dose_date, dose_id),
"Multiple doses exist for the same dose_date. Update dose_id to identify unique doses."
dataset_ex,
unique_by,
"Multiple doses exist for the same `dose_date`. Update `dose_id` to identify unique doses."
)


# filter EX based on user-specified condition
if (!is.null(quo_get_expr(filter_ex))) {
dataset_ex <- dataset_ex %>%
Expand Down
Loading

0 comments on commit dfb6489

Please sign in to comment.