Skip to content

Commit 7f80abd

Browse files
committed
Fix for resolution - if all differences less than tolerance, return 1
Fixes #6562
1 parent 381d9bd commit 7f80abd

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

R/utilities-resolution.R

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
#' The resolution is the smallest non-zero distance between adjacent
44
#' values. If there is only one unique value, then the resolution is defined
55
#' to be one. If x is an integer vector, then it is assumed to represent a
6-
#' discrete variable, and the resolution is 1.
6+
#' discrete variable, and the resolution is 1. If the differences are all smaller
7+
#' than the tolerance, set resolution to 1.
78
#'
89
#' @param x numeric vector
910
#' @param zero should a zero value be automatically included in the
@@ -33,5 +34,11 @@ resolution <- function(x, zero = TRUE, discrete = FALSE) {
3334
}
3435
d <- diff(sort(x))
3536
tolerance <- sqrt(.Machine$double.eps)
37+
38+
if(all(d < tolerance)){
39+
return(1)
40+
}
41+
3642
min(d[d > tolerance])
43+
3744
}

man/resolution.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)