From 87b2f34e45318855eb27116add70e102500c880d Mon Sep 17 00:00:00 2001 From: John Kirkpatrick <133956382+Puzzled-Face@users.noreply.github.com> Date: Tue, 10 Oct 2023 11:33:14 +0100 Subject: [PATCH] Remove noOverlap (#695) --- R/helpers.R | 36 ++++++++++++++++++++++++++---------- man/noOverlap.Rd | 21 --------------------- 2 files changed, 26 insertions(+), 31 deletions(-) delete mode 100644 man/noOverlap.Rd diff --git a/R/helpers.R b/R/helpers.R index 68730c23d..38448d6ed 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -103,19 +103,35 @@ matchTolerance <- function(x, table) { !is.na(matchTolerance(x = x, table = table)) } -##' Check overlap of two character vectors +##' checks for whole numbers (integers) ##' -##' @param a first character vector -##' @param b second character vector -##' @return returns TRUE if there is no overlap between the two character -##' vectors, otherwise FALSE +##' @param x the numeric vector +##' @param tol the tolerance +##' @return TRUE or FALSE for each element of x ##' ##' @keywords internal -noOverlap <- function(a, b) { - identical( - intersect(a, b), - character(0) - ) +is.wholenumber <- function(x, tol = .Machine$double.eps^0.5) { + abs(x - round(x)) < tol +} + + +##' Safe conversion to integer vector +##' +##' @param x the numeric vector +##' @return the integer vector +##' +##' @keywords internal +safeInteger <- function(x) { + testres <- is.wholenumber(x) + if (!all(testres)) { + notInt <- which(!testres) + stop(paste( + "elements", + paste(notInt, sep = ", "), + "of vector are not integers!" + )) + } + as.integer(x) } ##' Predicate checking for a probability diff --git a/man/noOverlap.Rd b/man/noOverlap.Rd deleted file mode 100644 index 20526f8f3..000000000 --- a/man/noOverlap.Rd +++ /dev/null @@ -1,21 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R -\name{noOverlap} -\alias{noOverlap} -\title{Check overlap of two character vectors} -\usage{ -noOverlap(a, b) -} -\arguments{ -\item{a}{first character vector} - -\item{b}{second character vector} -} -\value{ -returns TRUE if there is no overlap between the two character -vectors, otherwise FALSE -} -\description{ -Check overlap of two character vectors -} -\keyword{internal}