Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 36 additions & 5 deletions R/standalone-survival.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# ---
# repo: tidymodels/parsnip
# file: standalone-survival.R
# last-updated: 2023-12-08
# last-updated: 2024-01-10
# license: https://unlicense.org
# ---

# This file provides a portable set of helper functions for survival analysis.
#

# ## Changelog
# 2024-01-10
# * .filter_eval_time() gives more informative warning.
#
# 2023-12-08
# * move .filter_eval_time to this file
# * move .filter_eval_time() to this file
#
# 2023-11-09
# * make sure survival vectors are unnamed.
Expand Down Expand Up @@ -132,10 +135,38 @@
)
}
if (!identical(eval_time, eval_time_0)) {
diffs <- setdiff(eval_time_0, eval_time)
cli::cli_warn("There {?was/were} {length(diffs)} inappropriate evaluation
time point{?s} that {?was/were} removed.", call = NULL)
diffs <- length(eval_time_0) - length(eval_time)

offenders <- character()

n_na <- sum(is.na(eval_time_0))
if (n_na > 0) {
offenders <- c(offenders, "*" = "{n_na} missing value{?s}.")
}

n_inf <- sum(is.infinite(eval_time_0))
if (n_inf > 0) {
offenders <- c(offenders, "*" = "{n_inf} infinite value{?s}.")
}

n_neg <- sum(eval_time_0 < 0, na.rm = TRUE)
if (n_neg > 0) {
offenders <- c(offenders, "*" = "{n_neg} negative value{?s}.")
}

n_dup <- diffs - n_na - n_inf - n_neg
if (n_dup > 0) {
offenders <- c(offenders, "*" = "{n_dup} duplicate value{?s}.")
}

cli::cli_warn(
c(
"There {?was/were} {diffs} inappropriate evaluation time \\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤩

point{?s} that {?was/were} removed. {?It was/They were}:",
offenders
),
call = NULL
)
}
eval_time
}
11 changes: 8 additions & 3 deletions tests/testthat/_snaps/standalone-survival.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
parsnip:::.filter_eval_time(times_duplicated)
Condition
Warning:
There were 0 inappropriate evaluation time points that were removed.
There were 11 inappropriate evaluation time points that were removed. They were:
* 11 duplicate values.
Output
[1] 0 1 2 3 4 5 6 7 8 9 10

Expand All @@ -22,7 +23,10 @@
parsnip:::.filter_eval_time(times_remove_plural)
Condition
Warning:
There were 3 inappropriate evaluation time points that were removed.
There were 3 inappropriate evaluation time points that were removed. They were:
* 1 missing value.
* 1 infinite value.
* 1 negative value.
Output
[1] 0 1 2 3 4 5 6 7 8 9 10

Expand All @@ -32,7 +36,8 @@
parsnip:::.filter_eval_time(times_remove_singular)
Condition
Warning:
There was 1 inappropriate evaluation time point that was removed.
There was 1 inappropriate evaluation time point that was removed. It was:
* 1 negative value.
Output
[1] 0 1 2 3 4 5 6 7 8 9 10