R/set_tolerance.R

Defines functions get_tolerance set_tolerance

Documented in get_tolerance set_tolerance

#' Set Tolerance Level for Comparisons
#'
#' @description
#' Sets the numeric tolerance for floating-point comparisons, allowing small differences
#' within the tolerance to be treated as equal.
#'
#' @param tolerance A non-negative numeric value specifying the tolerance level.
#' @return Invisible \code{NULL}. Called for its side effect of updating the tolerance setting.
#' @keywords internal
set_tolerance <- function(tolerance = 0) {
  if (!is.numeric(tolerance) || tolerance < 0) {
    stop("Tolerance must be a non-negative numeric value.")
  }
  .clincompare_env$tolerance <- tolerance
  message("Tolerance set to ", tolerance)
  invisible(NULL)
}

#' Get Tolerance Level for Comparisons
#'
#' Retrieves the currently set tolerance level for numeric comparisons.
#'
#' @return The current tolerance level as a numeric value.
#' @keywords internal
get_tolerance <- function() {
  .clincompare_env$tolerance
}

Try the clinCompare package in your browser

Any scripts or data that you put into this service are public.

clinCompare documentation built on Feb. 19, 2026, 1:07 a.m.