tests/testthat/test-derive_var_trtedtm.R

test_that("TRTEDTM variable is added", {
  adsl <- tibble::tibble(STUDYID = "STUDY", USUBJID = 1:3)
  ex <- tibble::tribble(
    ~USUBJID, ~EXENDTC, ~EXSEQ, ~EXDOSE, ~EXTRT,
    1L, "2020-01-01", 1, 12, "ACTIVE",
    1L, "2020-02-03", 2, 9, "ACTIVE",
    2L, "2020-01-02", 1, 0, "PLACEBO",
    3L, "2020-03-13", 1, 14, "ACTIVE",
    3L, "2020-03-21", 2, 0, "ACTIVE"
  )

  expected_output <- mutate(
    adsl,
    TRTEDTM = as_iso_dtm(c(
      "2020-02-03T23:59:59",
      "2020-01-02T23:59:59",
      "2020-03-13T23:59:59"
    ))
  )

  actual_output <- derive_var_trtedtm(adsl, dataset_ex = ex, subject_keys = vars(USUBJID))

  expect_dfs_equal(
    base = expected_output,
    compare = actual_output,
    keys = "USUBJID"
  )
})
epijim/admiral documentation built on Feb. 13, 2022, 12:15 a.m.