Skip to content

Commit

Permalink
new error message and check
Browse files Browse the repository at this point in the history
  • Loading branch information
mattheaphy committed Jun 23, 2024
1 parent 385ded1 commit 4f74f79
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions R/expose.R
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ expose <- function(.data,
levels(.data$status) <- status_levels
}

if (default_status %in% target_status) {
rlang::abort(
"`default_status` is not allowed to be the same as `target_status`"
)
}

# pre-exposure updates
res <- .data |>
filter(issue_date < end_date,
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test-expose.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ test_that("Date format checks work", {
regexp = "Missing values are not allowed in the `issue_date`")
})

test_that("An error is thrown if the default status is a target status", {
all_deaths <- dplyr::tribble(
~pol_num, ~status, ~issue_date, ~term_date,
1, "Death", as.Date("2011-05-27"), as.Date("2012-03-17"),
2, "Death", as.Date("2011-05-27"), as.Date("2012-09-17"))
expect_error(all_deaths |>
expose(end_date = "2022-12-31", target_status = c("Death", "Surrender")),
regexp = "`default_status` is not allowed to be the same as `target_status"
)
})

# split exposure tests

test_that("expose_split() fails when passed non-calendar exposures", {
Expand Down

0 comments on commit 4f74f79

Please sign in to comment.