From b01413c9abb1d457250b03c5641a6c681f849386 Mon Sep 17 00:00:00 2001 From: Emily de la Rua <59304861+edelarua@users.noreply.github.com> Date: Mon, 12 Aug 2024 10:40:44 -0400 Subject: [PATCH] Fix `g_km` bug when multiple estimates are made at max time (#1280) Fixes #1279 --- NEWS.md | 1 + R/g_km.R | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index b1f5680933..09c3f61482 100644 --- a/NEWS.md +++ b/NEWS.md @@ -13,6 +13,7 @@ * Fixed defaults for formats and labels in `get_formats_from_stats` and `get_labels_from_stats`. * Fixed bug for linear scaling factor (`scale` parameter) being applied to response but not to rate in `h_glm_count` while all distributions have logarithmic link function. * Fixed bug in `decorate_grob` that did not handle well empty strings or `NULL` values for title and footers. +* Fixed bug in `g_km` that caused an error when multiple records in the data had estimates at max time. ### Miscellaneous diff --git a/R/g_km.R b/R/g_km.R index f4d2ed4bf9..01f4b641d2 100644 --- a/R/g_km.R +++ b/R/g_km.R @@ -378,8 +378,8 @@ g_km <- function(df, y_rng <- ylim[2] - ylim[1] - if (yval == "Survival" && data$estimate[data$time == max_time2] > ylim[1] + 0.09 * y_rng && - data$estimate[data$time == max_time2] < ylim[1] + 0.5 * y_rng) { # nolint + if (yval == "Survival" && all(data$estimate[data$time == max_time2] > ylim[1] + 0.09 * y_rng) && + all(data$estimate[data$time == max_time2] < ylim[1] + 0.5 * y_rng)) { # nolint gg_plt <- gg_plt + theme( legend.position.inside = c(1, 0.5),