Skip to content

Commit

Permalink
merge from ramio
Browse files Browse the repository at this point in the history
Merge branch '16_calculate_study_day@devel' of github.com:pharmaverse/sdtm.oak into 16_calculate_study_day@devel

# Conflicts:
#	R/calculate_study_day.R
  • Loading branch information
Rosemary Li committed Feb 19, 2024
2 parents d651028 + 7e92d53 commit 81d5804
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
21 changes: 6 additions & 15 deletions R/calculate_study_day.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#' calculate_study_day(ae, dm, "RFSTDTC", "AESTDTC", "AESTDY")
#'
calculate_study_day <- function(sdtm_in,
dm_domain,
refdt = "RFSTDTC",
tgdt,
study_day_var,
dm_domain = "DM",
Expand Down Expand Up @@ -120,22 +122,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 81d5804

Please sign in to comment.