Skip to content

Commit

Permalink
Updating create_dcut() to allow for NA as a datacut date
Browse files Browse the repository at this point in the history
  • Loading branch information
alanaharris22 committed Dec 13, 2023
1 parent be7bfda commit e579eec
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
1 change: 0 additions & 1 deletion .lintr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ linters: linters_with_defaults(
line_length_linter(100),
object_usage_linter=NULL,
infix_spaces_linter=NULL,
indentation_linter=NULL,
cyclocomp_linter(complexity_limit = 22)
)
exclusions: list(
Expand Down
6 changes: 3 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
- Added a "Report a bug" link to `{datacutr}` website (#182)

## Updates of Existing Functions
- Update to `impute_dcutdtc()`, `date_cut()` and `special_dm_cut()` functions to allow for
datacut date to be null. In this case, all records for this patient
will be kept/left unchanged.
- Update to `impute_dcutdtc()`, `create_dcut()`, `date_cut()` and `special_dm_cut()` functions
to allow for datacut date to be null. In this case, all records for this patient will be
kept/left unchanged.
- Warning added to `process_cut` if expected dataset `dm` is missing

## Breaking Changes
Expand Down
9 changes: 7 additions & 2 deletions R/create_dcut.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' @param ds_date_var Character date/time variable in the DS SDTMv to be compared against the
#' datacut date
#' @param filter Condition to filter patients in DS, should give 1 row per patient
#' @param cut_date Datacut date/time, e.g. "2022-10-22"
#' @param cut_date Datacut date/time, e.g. "2022-10-22", or NA if no date cut is to be applied
#' @param cut_description Datacut date/time description, e.g. "Clinical Cut Off Date"
#'
#' @author Alana Harris
Expand Down Expand Up @@ -74,13 +74,18 @@ create_dcut <- function(dataset_ds,
mutate(DCUTDTC = cut_date) %>%
mutate(DCUTDESC = cut_description) %>%
impute_dcutdtc(dsin = ., varin = DCUTDTC, varout = DCUTDTM) %>%
filter(., DCUTDTM >= DCUT_TEMP_DATE) %>%
filter(., (!is.na(DCUTDTM) & DCUTDTM >= DCUT_TEMP_DATE) | is.na(DCUTDTM)) %>%
filter_if(filter) %>%
subset(select = c(USUBJID, DCUTDTC, DCUTDTM, DCUTDESC))

assert_that(
(length(get_duplicates(dataset$USUBJID)) == 0),
msg = "Duplicate patients in the final returned dataset, please update."
)

# Print message if cut date is null
ifelse(any(is.na(mutate(dataset, DCUTDTM))) == TRUE,
print("At least 1 patient with missing datacut date."), NA
)
dataset
}
2 changes: 1 addition & 1 deletion man/create_dcut.Rd

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

22 changes: 22 additions & 0 deletions tests/testthat/test-create_dcut.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,25 @@ test_that("One observation in DCUT", {
expected_dcut
)
})

# Test 2 - Cut date as NA
expected_dcutna <- tibble::tribble(
~USUBJID, ~DCUTDTC, ~DCUTDTM, ~DCUTDESC,
"subject1", NA, NA, "Patients with Informed Consent",
"subject2", NA, NA, "Patients with Informed Consent",
"subject3", NA, NA, "Patients with Informed Consent",
"subject4", NA, NA, "Patients with Informed Consent"
)

test_that("One observation in DCUT", {
expect_equal(
create_dcut(
dataset_ds = input_ds,
ds_date_var = DSSTDTC,
filter = DSDECOD == "INFORMED CONSENT",
cut_date = NA,
cut_description = "Patients with Informed Consent"
),
expected_dcutna
)
})

0 comments on commit e579eec

Please sign in to comment.