From 9ad8dafedb6669b6fcee1c36740cfe94787b2289 Mon Sep 17 00:00:00 2001
From: Rosemary Li
Date: Mon, 12 Feb 2024 01:53:25 +0000
Subject: [PATCH] Revert "replace nested ifelse with case when per lintr
suggestion"
This reverts commit f6d467bd015993b4e98869959c1f8c4e793b0578.
---
R/calculate_study_day.R | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/R/calculate_study_day.R b/R/calculate_study_day.R
index 49fcf1c6..f2f66fb4 100644
--- a/R/calculate_study_day.R
+++ b/R/calculate_study_day.R
@@ -123,14 +123,20 @@ calculate_study_day <- function(sdtm_in,
}
)
- sdtm_in <- sdtm_in |> dplyr::mutate(
- {{ study_day_var }} := dplyr::case_when(
- {{ refdt_vector }} <= {{ tgdt_vector }} ~ {{ refdt_vector }} - {{ tgdt_vector }} + 1,
- {{ refdt_vector }} > {{ tgdt_vector }} ~ {{ tgdt_vector }} - {{ refdt_vector }},
- .default = NA
+ refdt_vector <- sdtm_in[[refdt]]
+ tgdt_vector <- sdtm_in[[tgdt]]
+
+ res <- ifelse(
+ test = refdt_vector <= tgdt_vector,
+ yes = refdt_vector - tgdt_vector + 1L,
+ no = ifelse(
+ test = refdt_vector > tgdt_vector,
+ yes = tgdt_vector - refdt_vector,
+ no = NA
)
)
- sdtm_in <- sdtm_in[c(original_variables, study_day_var)]
+ sdtm_in <- sdtm_in[original_variables]
+ sdtm_in[study_day_var] <- res
return(sdtm_in)
}