Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6a2a54b
#2652 derive_vars_joined_summary: first draft
bundfussr Apr 29, 2025
bc097f7
#2652 derive_vars_joined_summary: add test for rethrown error
bundfussr Apr 30, 2025
fb5740f
Merge branch 'main' into 2652_derive_vars_joined_summary
bundfussr May 5, 2025
34bc8f8
#2652 derive_vars_joined_summary: add examples
bundfussr May 5, 2025
78d7bca
#2652 derive_vars_joined_summary: update documentation and changelog
bundfussr May 6, 2025
43402bf
#2652 derive_vars_joined_summary: finalize
bundfussr May 7, 2025
6a7dd44
#2652 derive_vars_joined_summary: style files
bundfussr May 7, 2025
7d90047
#2652 derive_vars_joined_summary: fix spelling
bundfussr May 7, 2025
2c365e2
#2652 derive_vars_joined_summary: update "Generic Derivations" vignette
bundfussr May 7, 2025
455c1ef
#2652 derive_vars_joined_summary: fix lintr check
bundfussr May 7, 2025
ff3837f
Merge branch 'main' into 2652_derive_vars_joined_summary
bundfussr May 12, 2025
6c61ae0
Merge branch 'main' into 2652_derive_vars_joined_summary
bundfussr May 12, 2025
a0e235b
#2652 derive_vars_joined_summary: add more details to examples
bundfussr May 14, 2025
0191d0e
#2652 derive_vars_joined_summary: fix typo
bundfussr May 14, 2025
454371e
#2652 derive_vars_joined_summary: add examples for selecting records
bundfussr May 20, 2025
a8926e5
Merge branch 'main' into 2652_derive_vars_joined_summary
bundfussr May 20, 2025
736a5a8
Merge branch 'main' into 2652_derive_vars_joined_summary
bundfussr May 21, 2025
444bad3
#2652 derive_vars_joined_summary: update examples introduction
bundfussr May 21, 2025
a04b4fb
Merge branch 'main' into 2652_derive_vars_joined_summary
bundfussr May 21, 2025
0857404
Merge branch 'main' into 2652_derive_vars_joined_summary
bundfussr May 22, 2025
dd7369e
Merge branch 'main' into 2652_derive_vars_joined_summary
bundfussr May 22, 2025
846415a
#2652 derive_vars_joined_summary: move USUBJID in last example
bundfussr May 22, 2025
72b63f5
#2652 derive_vars_joined_summary: fix R-CMD checks
bundfussr May 22, 2025
e28be10
fix: #2652 borken template go brrrrr
bms63 May 23, 2025
870ac43
#2652 derive_vars_joined_summary: fix template and make DOSEON deriva…
bundfussr May 23, 2025
9fe7ffb
#2652 derive_vars_joined_summary: add note for DOSEON derivation
bundfussr May 23, 2025
6712fed
Merge branch 'main' into 2652_derive_vars_joined_summary
bms63 May 23, 2025
e9dbc74
#2652 derive_vars_joined_summary: update man
bundfussr May 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export(derive_vars_duration)
export(derive_vars_dy)
export(derive_vars_extreme_event)
export(derive_vars_joined)
export(derive_vars_joined_summary)
export(derive_vars_merged)
export(derive_vars_merged_lookup)
export(derive_vars_period)
Expand Down Expand Up @@ -280,6 +281,7 @@ importFrom(rlang,syms)
importFrom(rlang,type_of)
importFrom(rlang,zap)
importFrom(stats,setNames)
importFrom(stringr,fixed)
importFrom(stringr,str_c)
importFrom(stringr,str_count)
importFrom(stringr,str_detect)
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
- The output of the structured examples used for complex functions is
displayed in the help pages in RStudio.

- New function `derive_vars_joined_summary()` to derive summary variables from
selected records of an additional dataset where the selection depends on
variables from both the input dataset and the additional dataset. For example,
the cumulative dose up to each adverse event in `ADAE` can be derived with the
new function. (#2652)

- New lab grading metadata for US (Conventional) units for the three grading criteria
`admiral` already produces for SI units (#2557).
- `atoxgr_criteria_ctcv4_uscv` (NCI-CTCAEv4 criteria)
Expand All @@ -34,6 +40,7 @@ the `filter_add` argument is used. (#2863)
## Breaking Changes

- Lab grading metadata `atoxgr_criteria_ctcv4()`, `atoxgr_criteria_ctcv5()` and `atoxgr_criteria_daids()` variable `SI_UNIT_CHECK` renamed to `UNIT_CHECK` (#2557).

- The values of the variable specified for `tmp_obs_nr_var` in
`derive_vars_joined()`, `derive_var_joined_exist_flag()`, `filter_joined()` are
now populated differently if there are multiple records in `dataset` or
Expand Down
2 changes: 1 addition & 1 deletion R/admiral-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#' inform is_call is_expression is_missing is_named list2 new_environment
#' parse_expr parse_exprs set_names sym syms type_of zap
#' @importFrom stats setNames
#' @importFrom stringr str_c str_count str_detect str_extract str_glue
#' @importFrom stringr fixed str_c str_count str_detect str_extract str_glue
#' str_length str_locate str_locate_all str_match str_remove
#' str_remove_all str_replace str_replace_all str_split str_starts
#' str_sub str_subset str_to_lower str_to_title str_to_upper
Expand Down
10 changes: 5 additions & 5 deletions R/derive_joined.R
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@
#'
#' @param check_type Check uniqueness?
#'
#' If `"warning"` or `"error"` is specified, the specified message is issued
#' if the observations of the (restricted) joined dataset are not unique with
#' respect to the by variables and the order.
#' If `"message"`, `"warning"` or `"error"` is specified, the specified
#' message is issued if the observations of the (restricted) joined dataset
#' are not unique with respect to the by variables and the order.
#'
#' This argument is ignored if `order` is not specified. In this case an error
#' is issued independent of `check_type` if the restricted joined dataset
Expand Down Expand Up @@ -837,7 +837,7 @@ derive_vars_joined <- function(dataset,
#' prior to the observation. For example, to identify AEs occurring on or
#' after seven days before a COVID AE. Thus `join_type = "all"` could be used.
#'
#' @permitted [join]
#' @permitted [join_type]
#'
#' @param tmp_obs_nr_var Temporary observation number
#'
Expand Down Expand Up @@ -1131,7 +1131,7 @@ get_joined_data <- function(dataset,
} else {
joined_data <- get_joined_sub_data(
data,
dataset_add = data_add,
dataset_add = data_add_to_join,
by_vars = by_vars_left,
tmp_obs_nr_var = tmp_obs_nr_var,
tmp_obs_nr_left = tmp_obs_nr_left,
Expand Down
56 changes: 45 additions & 11 deletions R/derive_merged.R
Original file line number Diff line number Diff line change
Expand Up @@ -1034,16 +1034,50 @@ derive_var_merged_summary <- function(dataset,
)

# Summarise the analysis value and merge to the original dataset
derive_vars_merged(
dataset,
dataset_add = derive_summary_records(
dataset_add = dataset_add,
by_vars = by_vars_right,
filter_add = !!filter_add,
set_values_to = new_vars,
) %>%
select(!!!by_vars_right, names(new_vars)),
by_vars = by_vars,
missing_values = missing_values
# If for one of the new variables no summary function is used, i.e., more than
# one record is created per by group, the error from signal_duplicates_records()
# need to be updated and the warning from dplyr needs to be suppressed as it
# is misleading.
tryCatch(
withCallingHandlers(
derive_vars_merged(
dataset,
dataset_add = derive_summary_records(
dataset_add = dataset_add,
by_vars = by_vars_right,
filter_add = !!filter_add,
set_values_to = new_vars,
) %>%
select(!!!by_vars_right, names(new_vars)),
by_vars = by_vars,
missing_values = missing_values
),
warning = function(cnd) {
if (any(str_detect(
cnd$message,
fixed("Returning more (or less) than 1 row per `summarise()` group was deprecated")
))) {
cnd_muffle(cnd)
}
}
),
duplicate_records = function(cnd) {
cli_abort(
c(
paste(
"After summarising, the dataset contains duplicate records with",
"respect to {.var {cnd$by_vars}}."
),
paste(
"Please check {.arg new_vars} if summary functions like {.fun mean},",
"{.fun sum}, ... are used on the right hand side."
),
i = "Run {.run admiral::get_duplicates_dataset()} to access the duplicate records"
),
class = cnd$class,
call = NULL,
by_vars = cnd$by_vars
)
}
)
}
10 changes: 5 additions & 5 deletions R/derive_var_obs_number.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
#' The new variable is set to the observation number for each by group. The
#' numbering starts with 1.
#'
#' @permitted [var]
#'
#' @param check_type Check uniqueness?
#'
#' If `"warning"` or `"error"` is specified, the specified message is issued
#' if the observations of the input dataset are not unique with respect to the
#' by variables and the order.
#' If `"message"`, `"warning"` or `"error"` is specified, the specified
#' message is issued if the observations of the input dataset are not unique
#' with respect to the by variables and the order.
#'
#'
#' @permitted `"none"`, `"warning"`, `"error"`
#' @permitted [msg_type]
#'
#' @details For each group (with respect to the variables specified for the
#' `by_vars` parameter) the first or last observation (with respect to the
Expand Down
Loading
Loading