Skip to content

Commit 1737006

Browse files
committed
also test status_y error messages
1 parent 8d59871 commit 1737006

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

R/ppc-censoring.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ ppc_km_overlay <- function(
9090
suggested_package("survival")
9191
suggested_package("ggfortify")
9292

93-
stopifnot(is.numeric(status_y))
94-
stopifnot(all(status_y %in% c(0, 1)))
93+
if (!is.numeric(status_y) || length(status_y) != length(y) || !all(status_y %in% c(0, 1))) {
94+
stop("`status_y` must be a numeric vector of 0s and 1s the same length as `y`.")
95+
}
9596

9697
if (!is.null(left_truncation_y)) {
9798
if (!is.numeric(left_truncation_y) || length(left_truncation_y) != length(y)) {

tests/testthat/test-ppc-censoring.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ test_that("ppc_km_overlay_grouped returns a ggplot object", {
3232
status_y = status_y2))
3333
})
3434

35+
test_that("ppc_km_overlay errors if bad status_y value", {
36+
skip_if_not_installed("ggfortify")
37+
expect_error(
38+
ppc_km_overlay(y, yrep, status_y = FALSE),
39+
"`status_y` must be a numeric vector of 0s and 1s the same length as `y`."
40+
)
41+
expect_error(
42+
ppc_km_overlay(y, yrep, status_y = 1:10),
43+
"`status_y` must be a numeric vector of 0s and 1s the same length as `y`."
44+
)
45+
expect_error(
46+
ppc_km_overlay(y, yrep, status_y = rep(10, length(y))),
47+
"`status_y` must be a numeric vector of 0s and 1s the same length as `y`."
48+
)
49+
})
50+
3551
test_that("ppc_km_overlay errors if bad left_truncation_y value", {
3652
skip_if_not_installed("ggfortify")
3753
expect_error(

0 commit comments

Comments
 (0)