From 114458562428c1eae7ee4b207e31157cb3bea5da Mon Sep 17 00:00:00 2001 From: Kamil Slowikowski Date: Sun, 21 Jan 2024 20:31:15 -0500 Subject: [PATCH] change how we handle Inf This should fix issue #252 --- DESCRIPTION | 2 +- R/utilities.R | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 58d9219..6ae98a2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: ggrepel -Version: 0.9.5 +Version: 0.9.5.9999 Authors@R: c( person("Kamil", "Slowikowski", email = "kslowikowski@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-2843-6370")), person("Alicia", "Schep", role = "ctb", comment = c(ORCID = "0000-0002-3915-0618")), diff --git a/R/utilities.R b/R/utilities.R index baa0022..78a0a7c 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -81,17 +81,21 @@ parse_safe <- function(text) { #' @noRd exclude_outside <- function(data, panel_scales) { if ("x.range" %in% names(panel_scales)) { - ix <- data$x >= panel_scales$x.range[1] & - data$x <= panel_scales$x.range[2] & - data$y >= panel_scales$y.range[1] & - data$y <= panel_scales$y.range[2] + xr <- panel_scales$x.range + yr <- panel_scales$y.range + ix <- inside(data$x, xr) & inside(data$y, yr) data <- data[ix,,drop=FALSE] } else if ("x_range" %in% names(panel_scales)) { - ix <- data$x >= panel_scales$x_range[1] & - data$x <= panel_scales$x_range[2] & - data$y >= panel_scales$y_range[1] & - data$y <= panel_scales$y_range[2] + xr <- panel_scales$x_range + yr <- panel_scales$y_range + ix <- inside(data$x, xr) & inside(data$y, yr) data <- data[ix,,drop=FALSE] } data } + +#' Exclude data points outside the panel ranges +#' @noRd +inside <- function(x, bounds) { + is.infinite(x) | (x <= bounds[2] & x >= bounds[1]) +}