From 7f80abd8aef3d2a66c1abaa0199d655799e7f169 Mon Sep 17 00:00:00 2001 From: Ted Laderas Date: Fri, 19 Sep 2025 10:54:17 -0400 Subject: [PATCH 1/4] Fix for resolution - if all differences less than tolerance, return 1 Fixes #6562 --- R/utilities-resolution.R | 9 ++++++++- man/resolution.Rd | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/R/utilities-resolution.R b/R/utilities-resolution.R index d7ada9bb7f..fa96cafd4f 100644 --- a/R/utilities-resolution.R +++ b/R/utilities-resolution.R @@ -3,7 +3,8 @@ #' The resolution is the smallest non-zero distance between adjacent #' values. If there is only one unique value, then the resolution is defined #' to be one. If x is an integer vector, then it is assumed to represent a -#' discrete variable, and the resolution is 1. +#' discrete variable, and the resolution is 1. If the differences are all smaller +#' than the tolerance, set resolution to 1. #' #' @param x numeric vector #' @param zero should a zero value be automatically included in the @@ -33,5 +34,11 @@ resolution <- function(x, zero = TRUE, discrete = FALSE) { } d <- diff(sort(x)) tolerance <- sqrt(.Machine$double.eps) + + if(all(d < tolerance)){ + return(1) + } + min(d[d > tolerance]) + } diff --git a/man/resolution.Rd b/man/resolution.Rd index 0207545570..580a13ca60 100644 --- a/man/resolution.Rd +++ b/man/resolution.Rd @@ -19,7 +19,8 @@ having a resolution of 1?} The resolution is the smallest non-zero distance between adjacent values. If there is only one unique value, then the resolution is defined to be one. If x is an integer vector, then it is assumed to represent a -discrete variable, and the resolution is 1. +discrete variable, and the resolution is 1. If the differences are all smaller +than the tolerance, set resolution to 1. } \examples{ resolution(1:10) From 5eb045613071cfcb5cbeeb74e0eca1f29df40127 Mon Sep 17 00:00:00 2001 From: Ted Laderas Date: Fri, 19 Sep 2025 13:14:32 -0400 Subject: [PATCH 2/4] update --- R/utilities-resolution.R | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/R/utilities-resolution.R b/R/utilities-resolution.R index fa96cafd4f..069b316c77 100644 --- a/R/utilities-resolution.R +++ b/R/utilities-resolution.R @@ -35,10 +35,6 @@ resolution <- function(x, zero = TRUE, discrete = FALSE) { d <- diff(sort(x)) tolerance <- sqrt(.Machine$double.eps) - if(all(d < tolerance)){ - return(1) - } - - min(d[d > tolerance]) + min(d[d > tolerance], 1) } From 970046673b1519271964ae87e2ec8607d29012e4 Mon Sep 17 00:00:00 2001 From: Ted Laderas Date: Fri, 19 Sep 2025 13:47:18 -0400 Subject: [PATCH 3/4] reverting back --- R/utilities-resolution.R | 4 ++++ man/resolution.Rd | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/R/utilities-resolution.R b/R/utilities-resolution.R index 069b316c77..61475d63ab 100644 --- a/R/utilities-resolution.R +++ b/R/utilities-resolution.R @@ -35,6 +35,10 @@ resolution <- function(x, zero = TRUE, discrete = FALSE) { d <- diff(sort(x)) tolerance <- sqrt(.Machine$double.eps) + if(all(d < tolerance)){ + return(1) + } + min(d[d > tolerance], 1) } diff --git a/man/resolution.Rd b/man/resolution.Rd index 580a13ca60..0207545570 100644 --- a/man/resolution.Rd +++ b/man/resolution.Rd @@ -19,8 +19,7 @@ having a resolution of 1?} The resolution is the smallest non-zero distance between adjacent values. If there is only one unique value, then the resolution is defined to be one. If x is an integer vector, then it is assumed to represent a -discrete variable, and the resolution is 1. If the differences are all smaller -than the tolerance, set resolution to 1. +discrete variable, and the resolution is 1. } \examples{ resolution(1:10) From 128392b6b80c79e9fe2bcfae44e311322d1ad2dc Mon Sep 17 00:00:00 2001 From: Ted Laderas Date: Fri, 19 Sep 2025 14:11:31 -0400 Subject: [PATCH 4/4] removing ",1" from line 42 --- R/utilities-resolution.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/utilities-resolution.R b/R/utilities-resolution.R index 61475d63ab..fa96cafd4f 100644 --- a/R/utilities-resolution.R +++ b/R/utilities-resolution.R @@ -39,6 +39,6 @@ resolution <- function(x, zero = TRUE, discrete = FALSE) { return(1) } - min(d[d > tolerance], 1) + min(d[d > tolerance]) }