From 93495dddde2d17b04fa45cb759453ffc4559d162 Mon Sep 17 00:00:00 2001 From: Daniel Sjoberg Date: Fri, 4 Aug 2023 09:20:14 -0700 Subject: [PATCH] addressing missing treatment start dates --- R/derive_var_ontrtfl.R | 4 ++-- tests/testthat/_snaps/derive_var_ontrtfl.md | 2 ++ tests/testthat/test-derive_var_ontrtfl.R | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/R/derive_var_ontrtfl.R b/R/derive_var_ontrtfl.R index cd6b47385a..b648030e83 100644 --- a/R/derive_var_ontrtfl.R +++ b/R/derive_var_ontrtfl.R @@ -238,12 +238,12 @@ derive_var_ontrtfl <- function(dataset, if (ignore_time_for_ref_end_date) { end_cond <- expr( (date(!!start_date) <= date(!!ref_end_date) + days(!!ref_end_window)) | - is.na(!!ref_end_date) + (!is.na(!!ref_start_date) & is.na(!!ref_end_date)) ) } else { end_cond <- expr( (!!start_date <= !!ref_end_date + days(!!ref_end_window)) | - is.na(!!ref_end_date) + (!is.na(!!ref_start_date) & is.na(!!ref_end_date)) ) } dataset <- mutate( diff --git a/tests/testthat/_snaps/derive_var_ontrtfl.md b/tests/testthat/_snaps/derive_var_ontrtfl.md index 5704854a1d..abf2891b84 100644 --- a/tests/testthat/_snaps/derive_var_ontrtfl.md +++ b/tests/testthat/_snaps/derive_var_ontrtfl.md @@ -8,6 +8,7 @@ 1 P01 2018-03-15 2019-01-01 NA 2022-12-01 Y 2 P02 2020-04-30 2019-01-01 NA 2022-03-15 Y 3 P03 2020-04-30 2019-01-01 NA Y + 4 P04 2020-04-30 NA --- @@ -19,4 +20,5 @@ 1 P01 2018-03-15 2019-01-01 NA 2022-12-01 2 P02 2020-04-30 2019-01-01 NA 2022-03-15 Y 3 P03 2020-04-30 2019-01-01 NA Y + 4 P04 2020-04-30 NA diff --git a/tests/testthat/test-derive_var_ontrtfl.R b/tests/testthat/test-derive_var_ontrtfl.R index 85768a7f94..8c0c9ad10d 100644 --- a/tests/testthat/test-derive_var_ontrtfl.R +++ b/tests/testthat/test-derive_var_ontrtfl.R @@ -411,6 +411,7 @@ test_that("derive_var_ontrtfl Test 15: if trt end date is missing, the obs may s "P01", ymd("2018-03-15"), ymd("2019-01-01"), NA, ymd("2022-12-01"), "P02", ymd("2020-04-30"), ymd("2019-01-01"), NA, ymd("2022-03-15"), "P03", ymd("2020-04-30"), ymd("2019-01-01"), NA, NA, + "P04", ymd("2020-04-30"), NA, NA, NA ) %>% as.data.frame()