From 2250a7ffe1ac1cc7fea414b5708b9a48a5642ed8 Mon Sep 17 00:00:00 2001 From: Ross Farrugia Date: Fri, 15 Nov 2024 10:25:47 +0000 Subject: [PATCH 1/5] #2523 add extra examples --- R/derive_var_joined_exist_flag.R | 53 +++++++++++++++++++++++++++++ man/derive_var_joined_exist_flag.Rd | 53 +++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) diff --git a/R/derive_var_joined_exist_flag.R b/R/derive_var_joined_exist_flag.R index 2cbaa57eb5..d653e84e6a 100644 --- a/R/derive_var_joined_exist_flag.R +++ b/R/derive_var_joined_exist_flag.R @@ -208,6 +208,7 @@ #' #' @examples #' library(tibble) +#' library(dplyr) #' #' # flag observations with a duration longer than 30 and #' # at, after, or up to 7 days before a COVID AE (ACOVFL == "Y") @@ -406,6 +407,58 @@ #' first_cond_upper = val.join == "++", #' filter_join = val == "0" & all(val.join %in% c("+", "++")) #' ) +#' +#' # Flag each dose which is lower than the previous dose per subject +#' ex <- tribble( +#' ~USUBJID, ~EXSTDTM, ~EXDOSE, +#' "1", "2024-01-01T08:00", 2, +#' "1", "2024-01-02T08:00", 4, +#' "2", "2024-01-01T08:30", 1, +#' "2", "2024-01-02T08:30", 4, +#' "2", "2024-01-03T08:30", 3, +#' "2", "2024-01-04T08:30", 2 +#' ) +#' +#' derive_var_joined_exist_flag( +#' ex, +#' dataset_add = ex, +#' by_vars = exprs(USUBJID), +#' order = exprs(EXSTDTM), +#' new_var = DOSREDFL, +#' tmp_obs_nr_var = tmp_dose_nr, +#' join_vars = exprs(EXDOSE), +#' join_type = "before", +#' filter_join = ( +#' tmp_dose_nr == tmp_dose_nr.join + 1 # Look only at adjacent doses +#' & EXDOSE > 0 & EXDOSE.join > 0 # Both doses are valid +#' & EXDOSE < EXDOSE.join # Dose is lower than previous +#' ) +#' ) +#' +#' # derive definitive deterioration flag as any deterioration by +#' # parameter that is not followed by a non-deterioration +#' adqs <- tribble( +#' ~USUBJID, ~PARAMCD, ~ADY, ~CHGCAT1, +#' "1", "QS1", 10, "Improved", +#' "1", "QS1", 21, "Improved", +#' "1", "QS1", 23, "Improved", +#' "1", "QS2", 32, "Worsened", +#' "1", "QS2", 42, "Improved", +#' "2", "QS1", 11, "Worsened", +#' "2", "QS1", 24, "Worsened" +#' ) +#' +#' derive_var_joined_exist_flag( +#' adqs, +#' dataset_add = adqs, +#' new_var = NODDFL, +#' by_vars = exprs(USUBJID, PARAMCD), +#' join_vars = exprs(CHGCAT1), +#' join_type = "after", +#' order = exprs(ADY), +#' filter_join = CHGCAT1.join != "Worsened" +#' ) %>% +#' mutate(DDETERFL = if_else(CHGCAT1 == "Worsened" & is.na(NODDFL), "Y", NA_character_)) derive_var_joined_exist_flag <- function(dataset, dataset_add, by_vars, diff --git a/man/derive_var_joined_exist_flag.Rd b/man/derive_var_joined_exist_flag.Rd index 9334f60eb5..bf899d6aa6 100644 --- a/man/derive_var_joined_exist_flag.Rd +++ b/man/derive_var_joined_exist_flag.Rd @@ -251,6 +251,7 @@ previous step. For the other observations it is set to \code{false_value}. } \examples{ library(tibble) +library(dplyr) # flag observations with a duration longer than 30 and # at, after, or up to 7 days before a COVID AE (ACOVFL == "Y") @@ -449,6 +450,58 @@ derive_var_joined_exist_flag( first_cond_upper = val.join == "++", filter_join = val == "0" & all(val.join \%in\% c("+", "++")) ) + +# Flag each dose which is lower than the previous dose per subject +ex <- tribble( + ~USUBJID, ~EXSTDTM, ~EXDOSE, + "1", "2024-01-01T08:00", 2, + "1", "2024-01-02T08:00", 4, + "2", "2024-01-01T08:30", 1, + "2", "2024-01-02T08:30", 4, + "2", "2024-01-03T08:30", 3, + "2", "2024-01-04T08:30", 2 +) + +derive_var_joined_exist_flag( + ex, + dataset_add = ex, + by_vars = exprs(USUBJID), + order = exprs(EXSTDTM), + new_var = DOSREDFL, + tmp_obs_nr_var = tmp_dose_nr, + join_vars = exprs(EXDOSE), + join_type = "before", + filter_join = ( + tmp_dose_nr == tmp_dose_nr.join + 1 # Look only at adjacent doses + & EXDOSE > 0 & EXDOSE.join > 0 # Both doses are valid + & EXDOSE < EXDOSE.join # Dose is lower than previous + ) +) + +# derive definitive deterioration flag as any deterioration by +# parameter that is not followed by a non-deterioration +adqs <- tribble( + ~USUBJID, ~PARAMCD, ~ADY, ~CHGCAT1, + "1", "QS1", 10, "Improved", + "1", "QS1", 21, "Improved", + "1", "QS1", 23, "Improved", + "1", "QS2", 32, "Worsened", + "1", "QS2", 42, "Improved", + "2", "QS1", 11, "Worsened", + "2", "QS1", 24, "Worsened" +) + +derive_var_joined_exist_flag( + adqs, + dataset_add = adqs, + new_var = NODDFL, + by_vars = exprs(USUBJID, PARAMCD), + join_vars = exprs(CHGCAT1), + join_type = "after", + order = exprs(ADY), + filter_join = CHGCAT1.join != "Worsened" +) \%>\% +mutate(DDETERFL = if_else(CHGCAT1 == "Worsened" & is.na(NODDFL), "Y", NA_character_)) } \seealso{ \code{\link[=filter_joined]{filter_joined()}}, \code{\link[=derive_vars_joined]{derive_vars_joined()}} From dde0ed4f0da0dd9a864090b82a70bf69701b50d5 Mon Sep 17 00:00:00 2001 From: Ross Farrugia Date: Fri, 15 Nov 2024 11:46:04 +0000 Subject: [PATCH 2/5] #2523 clean up comments --- R/derive_var_joined_exist_flag.R | 8 ++++---- man/derive_var_joined_exist_flag.Rd | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/R/derive_var_joined_exist_flag.R b/R/derive_var_joined_exist_flag.R index d653e84e6a..a8f507981a 100644 --- a/R/derive_var_joined_exist_flag.R +++ b/R/derive_var_joined_exist_flag.R @@ -408,7 +408,7 @@ #' filter_join = val == "0" & all(val.join %in% c("+", "++")) #' ) #' -#' # Flag each dose which is lower than the previous dose per subject +#' # flag each dose which is lower than the previous dose per subject #' ex <- tribble( #' ~USUBJID, ~EXSTDTM, ~EXDOSE, #' "1", "2024-01-01T08:00", 2, @@ -435,8 +435,8 @@ #' ) #' ) #' -#' # derive definitive deterioration flag as any deterioration by -#' # parameter that is not followed by a non-deterioration +#' # derive definitive deterioration flag as any deterioration (CHGCAT1 = "Worsened") +#' # by parameter that is not followed by a non-deterioration #' adqs <- tribble( #' ~USUBJID, ~PARAMCD, ~ADY, ~CHGCAT1, #' "1", "QS1", 10, "Improved", @@ -456,7 +456,7 @@ #' join_vars = exprs(CHGCAT1), #' join_type = "after", #' order = exprs(ADY), -#' filter_join = CHGCAT1.join != "Worsened" +#' filter_join = CHGCAT1.join != "Worsened" # flags if followed by a non-deterioration #' ) %>% #' mutate(DDETERFL = if_else(CHGCAT1 == "Worsened" & is.na(NODDFL), "Y", NA_character_)) derive_var_joined_exist_flag <- function(dataset, diff --git a/man/derive_var_joined_exist_flag.Rd b/man/derive_var_joined_exist_flag.Rd index bf899d6aa6..37f278e741 100644 --- a/man/derive_var_joined_exist_flag.Rd +++ b/man/derive_var_joined_exist_flag.Rd @@ -451,7 +451,7 @@ derive_var_joined_exist_flag( filter_join = val == "0" & all(val.join \%in\% c("+", "++")) ) -# Flag each dose which is lower than the previous dose per subject +# flag each dose which is lower than the previous dose per subject ex <- tribble( ~USUBJID, ~EXSTDTM, ~EXDOSE, "1", "2024-01-01T08:00", 2, @@ -478,8 +478,8 @@ derive_var_joined_exist_flag( ) ) -# derive definitive deterioration flag as any deterioration by -# parameter that is not followed by a non-deterioration +# derive definitive deterioration flag as any deterioration (CHGCAT1 = "Worsened") +# by parameter that is not followed by a non-deterioration adqs <- tribble( ~USUBJID, ~PARAMCD, ~ADY, ~CHGCAT1, "1", "QS1", 10, "Improved", @@ -499,7 +499,7 @@ derive_var_joined_exist_flag( join_vars = exprs(CHGCAT1), join_type = "after", order = exprs(ADY), - filter_join = CHGCAT1.join != "Worsened" + filter_join = CHGCAT1.join != "Worsened" # flags if followed by a non-deterioration ) \%>\% mutate(DDETERFL = if_else(CHGCAT1 == "Worsened" & is.na(NODDFL), "Y", NA_character_)) } From 4f8721ee0d2c2841b4f7a062a2168d6a585059d5 Mon Sep 17 00:00:00 2001 From: Ross Farrugia Date: Fri, 15 Nov 2024 11:57:47 +0000 Subject: [PATCH 3/5] #2523 styler --- R/derive_var_joined_exist_flag.R | 6 +++--- man/derive_var_joined_exist_flag.Rd | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/R/derive_var_joined_exist_flag.R b/R/derive_var_joined_exist_flag.R index a8f507981a..ece1f61442 100644 --- a/R/derive_var_joined_exist_flag.R +++ b/R/derive_var_joined_exist_flag.R @@ -430,8 +430,8 @@ #' join_type = "before", #' filter_join = ( #' tmp_dose_nr == tmp_dose_nr.join + 1 # Look only at adjacent doses -#' & EXDOSE > 0 & EXDOSE.join > 0 # Both doses are valid -#' & EXDOSE < EXDOSE.join # Dose is lower than previous +#' & EXDOSE > 0 & EXDOSE.join > 0 # Both doses are valid +#' & EXDOSE < EXDOSE.join # Dose is lower than previous #' ) #' ) #' @@ -458,7 +458,7 @@ #' order = exprs(ADY), #' filter_join = CHGCAT1.join != "Worsened" # flags if followed by a non-deterioration #' ) %>% -#' mutate(DDETERFL = if_else(CHGCAT1 == "Worsened" & is.na(NODDFL), "Y", NA_character_)) +#' mutate(DDETERFL = if_else(CHGCAT1 == "Worsened" & is.na(NODDFL), "Y", NA_character_)) derive_var_joined_exist_flag <- function(dataset, dataset_add, by_vars, diff --git a/man/derive_var_joined_exist_flag.Rd b/man/derive_var_joined_exist_flag.Rd index 37f278e741..17d648b26b 100644 --- a/man/derive_var_joined_exist_flag.Rd +++ b/man/derive_var_joined_exist_flag.Rd @@ -473,8 +473,8 @@ derive_var_joined_exist_flag( join_type = "before", filter_join = ( tmp_dose_nr == tmp_dose_nr.join + 1 # Look only at adjacent doses - & EXDOSE > 0 & EXDOSE.join > 0 # Both doses are valid - & EXDOSE < EXDOSE.join # Dose is lower than previous + & EXDOSE > 0 & EXDOSE.join > 0 # Both doses are valid + & EXDOSE < EXDOSE.join # Dose is lower than previous ) ) @@ -501,7 +501,7 @@ derive_var_joined_exist_flag( order = exprs(ADY), filter_join = CHGCAT1.join != "Worsened" # flags if followed by a non-deterioration ) \%>\% -mutate(DDETERFL = if_else(CHGCAT1 == "Worsened" & is.na(NODDFL), "Y", NA_character_)) + mutate(DDETERFL = if_else(CHGCAT1 == "Worsened" & is.na(NODDFL), "Y", NA_character_)) } \seealso{ \code{\link[=filter_joined]{filter_joined()}}, \code{\link[=derive_vars_joined]{derive_vars_joined()}} From 55c7f5c24bed5fa74ed15743231e1e6aed024ad9 Mon Sep 17 00:00:00 2001 From: Ross Farrugia Date: Fri, 15 Nov 2024 13:27:13 +0000 Subject: [PATCH 4/5] #2523 news --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index a9cc08ec4f..3c18e8d386 100644 --- a/NEWS.md +++ b/NEWS.md @@ -64,6 +64,8 @@ example, `">2.5 x ULN"` changed to `">2.5"` for grade 3. (#2534) - `derive_locf_records()` documentation example was fixed to display LOCF records. (#2461) +- `derive_var_joined_exist_flag()` documentation updated with extra examples. (#2523) + ## Various
From ad772c102c40694aa078901713c8f4e7909db439 Mon Sep 17 00:00:00 2001 From: Ross Farrugia Date: Fri, 15 Nov 2024 14:58:18 +0000 Subject: [PATCH 5/5] #2523 simplify examples --- R/derive_var_joined_exist_flag.R | 13 ++++++------- man/derive_var_joined_exist_flag.Rd | 13 ++++++------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/R/derive_var_joined_exist_flag.R b/R/derive_var_joined_exist_flag.R index ece1f61442..2a77f57ddf 100644 --- a/R/derive_var_joined_exist_flag.R +++ b/R/derive_var_joined_exist_flag.R @@ -208,7 +208,6 @@ #' #' @examples #' library(tibble) -#' library(dplyr) #' #' # flag observations with a duration longer than 30 and #' # at, after, or up to 7 days before a COVID AE (ACOVFL == "Y") @@ -416,7 +415,8 @@ #' "2", "2024-01-01T08:30", 1, #' "2", "2024-01-02T08:30", 4, #' "2", "2024-01-03T08:30", 3, -#' "2", "2024-01-04T08:30", 2 +#' "2", "2024-01-04T08:30", 2, +#' "2", "2024-01-05T08:30", 2 #' ) #' #' derive_var_joined_exist_flag( @@ -451,14 +451,13 @@ #' derive_var_joined_exist_flag( #' adqs, #' dataset_add = adqs, -#' new_var = NODDFL, +#' new_var = DDETERFL, #' by_vars = exprs(USUBJID, PARAMCD), #' join_vars = exprs(CHGCAT1), -#' join_type = "after", +#' join_type = "all", #' order = exprs(ADY), -#' filter_join = CHGCAT1.join != "Worsened" # flags if followed by a non-deterioration -#' ) %>% -#' mutate(DDETERFL = if_else(CHGCAT1 == "Worsened" & is.na(NODDFL), "Y", NA_character_)) +#' filter_join = all(CHGCAT1.join == "Worsened" | ADY > ADY.join) +#' ) derive_var_joined_exist_flag <- function(dataset, dataset_add, by_vars, diff --git a/man/derive_var_joined_exist_flag.Rd b/man/derive_var_joined_exist_flag.Rd index 17d648b26b..c1401f5423 100644 --- a/man/derive_var_joined_exist_flag.Rd +++ b/man/derive_var_joined_exist_flag.Rd @@ -251,7 +251,6 @@ previous step. For the other observations it is set to \code{false_value}. } \examples{ library(tibble) -library(dplyr) # flag observations with a duration longer than 30 and # at, after, or up to 7 days before a COVID AE (ACOVFL == "Y") @@ -459,7 +458,8 @@ ex <- tribble( "2", "2024-01-01T08:30", 1, "2", "2024-01-02T08:30", 4, "2", "2024-01-03T08:30", 3, - "2", "2024-01-04T08:30", 2 + "2", "2024-01-04T08:30", 2, + "2", "2024-01-05T08:30", 2 ) derive_var_joined_exist_flag( @@ -494,14 +494,13 @@ adqs <- tribble( derive_var_joined_exist_flag( adqs, dataset_add = adqs, - new_var = NODDFL, + new_var = DDETERFL, by_vars = exprs(USUBJID, PARAMCD), join_vars = exprs(CHGCAT1), - join_type = "after", + join_type = "all", order = exprs(ADY), - filter_join = CHGCAT1.join != "Worsened" # flags if followed by a non-deterioration -) \%>\% - mutate(DDETERFL = if_else(CHGCAT1 == "Worsened" & is.na(NODDFL), "Y", NA_character_)) + filter_join = all(CHGCAT1.join == "Worsened" | ADY > ADY.join) +) } \seealso{ \code{\link[=filter_joined]{filter_joined()}}, \code{\link[=derive_vars_joined]{derive_vars_joined()}}