From 7e92d53a5002b95fa5c55873a821d1dba5c86ef6 Mon Sep 17 00:00:00 2001 From: Ramiro Magno Date: Sat, 17 Feb 2024 02:07:32 +0000 Subject: [PATCH] Update `calculate_study_day()` Fix usage of default missing value in parameter `dm_domain` and calculate study day with more straightforward expression. --- R/calculate_study_day.R | 21 +++++---------------- man/calculate_study_day.Rd | 2 +- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/R/calculate_study_day.R b/R/calculate_study_day.R index 2d11a548..36e3f6e2 100644 --- a/R/calculate_study_day.R +++ b/R/calculate_study_day.R @@ -36,7 +36,7 @@ #' calculate_study_day(ae, dm, "RFSTDTC", "AESTDTC", "AESTDY") #' calculate_study_day <- function(sdtm_in, - dm_domain = DM, + dm_domain, refdt = "RFSTDTC", tgdt, study_day_var, @@ -120,22 +120,11 @@ calculate_study_day <- function(sdtm_in, } ) - refdt_vector <- sdtm_in[[refdt]] - tgdt_vector <- sdtm_in[[tgdt]] + ref <- sdtm_in[[refdt]] + tgt <- sdtm_in[[tgdt]] - dy_cal_func <- function(ref, tgt) { - if (is.na(ref) || is.na(tgt)) { - res <- NA - } else if (ref <= tgt) { - res <- ref - tgt + 1L - } else if (ref > tgt) { - res <- tgt - ref - } else { - res <- NA - } - return(res) - } - res <- mapply(dy_cal_func, refdt_vector, tgdt_vector, SIMPLIFY = TRUE, USE.NAMES = FALSE) + # SDTMIG 4.4.4 Use of the Study Day Variables + res <- ifelse(tgt > ref, tgt - ref + 1L, tgt - ref) sdtm_in <- sdtm_in[original_variables] sdtm_in[study_day_var] <- res diff --git a/man/calculate_study_day.Rd b/man/calculate_study_day.Rd index 5382e46a..724b6dfe 100644 --- a/man/calculate_study_day.Rd +++ b/man/calculate_study_day.Rd @@ -6,7 +6,7 @@ \usage{ calculate_study_day( sdtm_in, - dm_domain = DM, + dm_domain, refdt = "RFSTDTC", tgdt, study_day_var,