Skip to content

Commit

Permalink
Update calculate_study_day()
Browse files Browse the repository at this point in the history
Fix usage of default missing value in parameter `dm_domain` and calculate study day with more straightforward expression.
  • Loading branch information
ramiromagno committed Feb 17, 2024
1 parent 026f5a3 commit 7e92d53
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
21 changes: 5 additions & 16 deletions R/calculate_study_day.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion man/calculate_study_day.Rd

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

0 comments on commit 7e92d53

Please sign in to comment.