From 71b3611ca3ee4cf6e33129c49ca213ab58b28e08 Mon Sep 17 00:00:00 2001 From: Emil Hvitfeldt Date: Wed, 10 Jan 2024 10:28:48 -0800 Subject: [PATCH 1/4] give .filter_eval_time() more informative warning --- R/standalone-survival.R | 34 ++++++++++++++++++-- tests/testthat/_snaps/standalone-survival.md | 11 +++++-- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/R/standalone-survival.R b/R/standalone-survival.R index bf46c1346..e0fbc5da5 100644 --- a/R/standalone-survival.R +++ b/R/standalone-survival.R @@ -132,10 +132,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 \\ + point{?s} that {?was/were} removed. They were:", + offenders + ), + call = NULL + ) } eval_time } diff --git a/tests/testthat/_snaps/standalone-survival.md b/tests/testthat/_snaps/standalone-survival.md index 1546e3fdb..109c33dc4 100644 --- a/tests/testthat/_snaps/standalone-survival.md +++ b/tests/testthat/_snaps/standalone-survival.md @@ -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 @@ -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 @@ -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. They were: + * 1 negative value. Output [1] 0 1 2 3 4 5 6 7 8 9 10 From 77a52d9ebe6ce4d034626fe211c697f882bebdb9 Mon Sep 17 00:00:00 2001 From: Emil Hvitfeldt Date: Wed, 10 Jan 2024 10:30:15 -0800 Subject: [PATCH 2/4] update changelog --- R/standalone-survival.R | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/R/standalone-survival.R b/R/standalone-survival.R index e0fbc5da5..2e1a2d4f5 100644 --- a/R/standalone-survival.R +++ b/R/standalone-survival.R @@ -1,7 +1,7 @@ # --- # repo: tidymodels/parsnip # file: standalone-survival.R -# last-updated: 2023-12-08 +# last-updated: 2024-01-10 # license: https://unlicense.org # --- @@ -9,8 +9,11 @@ # # ## 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. From 25f07571269de0c2d8e151e3cfa0c2180ab3e6ef Mon Sep 17 00:00:00 2001 From: Emil Hvitfeldt Date: Thu, 11 Jan 2024 12:11:40 -0800 Subject: [PATCH 3/4] Update R/standalone-survival.R Co-authored-by: Hannah Frick --- R/standalone-survival.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/standalone-survival.R b/R/standalone-survival.R index 2e1a2d4f5..c655bbf5e 100644 --- a/R/standalone-survival.R +++ b/R/standalone-survival.R @@ -162,7 +162,7 @@ cli::cli_warn( c( "There {?was/were} {diffs} inappropriate evaluation time \\ - point{?s} that {?was/were} removed. They were:", + point{?s} that {?was/were} removed. {?It was/They were}:", offenders ), call = NULL From 353961f8ada694229715b151cbdde12e835b2699 Mon Sep 17 00:00:00 2001 From: Emil Hvitfeldt Date: Thu, 11 Jan 2024 12:14:08 -0800 Subject: [PATCH 4/4] update snapshot --- tests/testthat/_snaps/standalone-survival.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/_snaps/standalone-survival.md b/tests/testthat/_snaps/standalone-survival.md index 109c33dc4..4e1a67e42 100644 --- a/tests/testthat/_snaps/standalone-survival.md +++ b/tests/testthat/_snaps/standalone-survival.md @@ -36,7 +36,7 @@ parsnip:::.filter_eval_time(times_remove_singular) Condition Warning: - There was 1 inappropriate evaluation time point that was removed. They were: + 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