|
1 | 1 | # --- |
2 | 2 | # repo: tidymodels/parsnip |
3 | 3 | # file: standalone-survival.R |
4 | | -# last-updated: 2023-12-08 |
| 4 | +# last-updated: 2024-01-10 |
5 | 5 | # license: https://unlicense.org |
6 | 6 | # --- |
7 | 7 |
|
8 | 8 | # This file provides a portable set of helper functions for survival analysis. |
9 | 9 | # |
10 | 10 |
|
11 | 11 | # ## Changelog |
| 12 | +# 2024-01-10 |
| 13 | +# * .filter_eval_time() gives more informative warning. |
| 14 | +# |
12 | 15 | # 2023-12-08 |
13 | | -# * move .filter_eval_time to this file |
| 16 | +# * move .filter_eval_time() to this file |
14 | 17 | # |
15 | 18 | # 2023-11-09 |
16 | 19 | # * make sure survival vectors are unnamed. |
|
132 | 135 | ) |
133 | 136 | } |
134 | 137 | if (!identical(eval_time, eval_time_0)) { |
135 | | - diffs <- setdiff(eval_time_0, eval_time) |
136 | | - cli::cli_warn("There {?was/were} {length(diffs)} inappropriate evaluation |
137 | | - time point{?s} that {?was/were} removed.", call = NULL) |
| 138 | + diffs <- length(eval_time_0) - length(eval_time) |
| 139 | + |
| 140 | + offenders <- character() |
| 141 | + |
| 142 | + n_na <- sum(is.na(eval_time_0)) |
| 143 | + if (n_na > 0) { |
| 144 | + offenders <- c(offenders, "*" = "{n_na} missing value{?s}.") |
| 145 | + } |
| 146 | + |
| 147 | + n_inf <- sum(is.infinite(eval_time_0)) |
| 148 | + if (n_inf > 0) { |
| 149 | + offenders <- c(offenders, "*" = "{n_inf} infinite value{?s}.") |
| 150 | + } |
138 | 151 |
|
| 152 | + n_neg <- sum(eval_time_0 < 0, na.rm = TRUE) |
| 153 | + if (n_neg > 0) { |
| 154 | + offenders <- c(offenders, "*" = "{n_neg} negative value{?s}.") |
| 155 | + } |
| 156 | + |
| 157 | + n_dup <- diffs - n_na - n_inf - n_neg |
| 158 | + if (n_dup > 0) { |
| 159 | + offenders <- c(offenders, "*" = "{n_dup} duplicate value{?s}.") |
| 160 | + } |
| 161 | + |
| 162 | + cli::cli_warn( |
| 163 | + c( |
| 164 | + "There {?was/were} {diffs} inappropriate evaluation time \\ |
| 165 | + point{?s} that {?was/were} removed. {?It was/They were}:", |
| 166 | + offenders |
| 167 | + ), |
| 168 | + call = NULL |
| 169 | + ) |
139 | 170 | } |
140 | 171 | eval_time |
141 | 172 | } |
0 commit comments