Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion R/utilities-resolution.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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])

Comment on lines +37 to +43
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. I think this can be solved with fewer computations by doing something min(d[d > tolerance], 1)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that's a good alternative

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, I completely messed up in that suggestion. Sorry about that.

You can revert to your old approach

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to remove the , 1 from the last call :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, will fix

}
3 changes: 2 additions & 1 deletion man/resolution.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading