Skip to content

Commit

Permalink
remove dm_domain default
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosemary Li committed Feb 21, 2024
1 parent fa26e73 commit 958453e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
13 changes: 6 additions & 7 deletions R/calculate_study_day.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
#' NA will be returned for those records.
#'
#' @param sdtm_in Input data frame that contains the target date.
#' @param dm_domain Reference date frame that contains the reference date.
#' @param tgdt Target date from `sdtm_in` that will be used to calculate the study
#' day.
#' @param study_day_var New study day variable name in the output. For
#' example, AESTDY for AE domain and CMSTDY for CM domain.
#' @param dm_domain Reference date frame that contains the reference date.
#' @param refdt Reference date from `dm_domain` that will be used as reference to
#' calculate the study day.
#' @param study_day_var New study day variable name in the output. For
#' example, AESTDY for AE domain and CMSTDY for CM domain.
#' @param merge_key Character to represents the merging key between `sdtm_in` and
#' `dm_domain`.
#'
Expand All @@ -33,16 +33,15 @@
#' )
#' ae$AESTDTC <- as.Date(ae$AESTDTC)
#' dm$RFSTDTC <- as.Date(dm$RFSTDTC)
#' calculate_study_day(ae, "AESTDTC", "AESTDY", "dm", "RFSTDTC")
#' calculate_study_day(ae, dm, "AESTDTC", "RFSTDTC", "AESTDY")
#'
calculate_study_day <- function(sdtm_in,
dm_domain,
tgdt,
refdt,
study_day_var,
dm_domain = "DM",
refdt = "RFSTDTC",
merge_key = "USUBJID") {
assertthat::assert_that(is.data.frame(sdtm_in))
dm_domain <- eval(parse(text = dm_domain))
assertthat::assert_that(is.data.frame(dm_domain))
assertthat::assert_that(
utils::hasName(dm_domain, refdt),
Expand Down
16 changes: 8 additions & 8 deletions man/calculate_study_day.Rd

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

16 changes: 8 additions & 8 deletions tests/testthat/test-calculate_study_day.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ test_that("`calculate_study_day()` works as expected for invalid input", {
"dm_domain is not a data frame"
)
expect_error(
calculate_study_day(iris, "d", "e", "iris", "b"),
calculate_study_day(iris, iris, "d", "e", "b"),
"dm_domain needs to have the variable of refdt"
)
expect_error(
calculate_study_day(iris, "e", "d", "iris", "Species"),
calculate_study_day(iris, iris, "d", "Species"),
"sdtm_in needs to have the variable of tgdt"
)
expect_error(
calculate_study_day(iris, "Petal.Length", "e", "iris", "Species"),
calculate_study_day(iris, iris, "Petal.Length", "Species", "e"),
"needs to have the variable of merge_key"
)
expect_error(
calculate_study_day(iris, "Petal.Length", 123L, "iris", "Species", "Species"),
calculate_study_day(iris, iris, "Petal.Length", "Species", 123L, "Species"),
"study_day_var is not a character vector"
)
expect_warning(
calculate_study_day(ae, "AESTDTC", "AENDY", "dm", "RFSTDTC"),
calculate_study_day(ae, dm, "AESTDTC", "RFSTDTC", "AENDY"),
"Target date and the returned study day doesn't match."
)

Expand All @@ -45,7 +45,7 @@ test_that("`calculate_study_day()` works as expected for invalid input", {
stringsAsFactors = FALSE
)
expect_warning(
calculate_study_day(ae, "AESTDTC", "AESTDY", "dm1", "RFSTDTC"),
calculate_study_day(ae, dm1, "AESTDTC", "RFSTDTC", "AESTDY"),
"Reference date is not unique for each patient!"
)

Expand All @@ -55,13 +55,13 @@ test_that("`calculate_study_day()` works as expected for invalid input", {
stringsAsFactors = FALSE
)
expect_warning(
calculate_study_day(ae, "AESTDTC", "AESTDY", "dm2", "RFSTDTC"),
calculate_study_day(ae, dm2, "AESTDTC", "RFSTDTC", "AESTDY"),
"Encountered errors when converting refdt to dates."
)
})

test_that("`calculate_study_day()` works as expected for valid input", {
res <- calculate_study_day(ae, "AESTDTC", "AESTDY", "dm", "RFSTDTC")
res <- calculate_study_day(ae, dm, "AESTDTC", "RFSTDTC", "AESTDY")
expected <- c(-31L, 1L, NA)
expect_equal(res$AESTDY, expected, tolerance = "1.5e-08")
})

0 comments on commit 958453e

Please sign in to comment.