R/is_whole_number.R

Defines functions is_whole_number

Documented in is_whole_number

#' Checks if x is a single, whole-number variable
#' @param x the number to check
#' @param tolerance the maximum error a number may deviate from a whole number,
#'   before it is labeled as a floating point value
#' @return TRUE or FALSE
#' @author Richèl Bilderbeek
#' @export
is_whole_number <- function(
  x,
  tolerance = .Machine$double.eps ^ 0.5
) {
  if (length(x) > 1) return(FALSE)
  if (!is.numeric(x)) return(FALSE)
  return(abs(x - round(x)) < tolerance)
}
richelbilderbeek/ribir documentation built on March 19, 2021, 3:55 a.m.