Skip to content

Commit 2e5fcbb

Browse files
authored
Fix for resolution - if all differences less than tolerance, return 1 (#6630)
1 parent 3d1e9b2 commit 2e5fcbb

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
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
}

0 commit comments

Comments
 (0)