diff --git a/R/Rules-methods.R b/R/Rules-methods.R index fe660b8c3..919329bb3 100644 --- a/R/Rules-methods.R +++ b/R/Rules-methods.R @@ -3017,7 +3017,7 @@ setMethod("stopTrial", prob_target <- stopping@prob_target ## checks - stopifnot(is.probability(prob_target)) + assert_probability(prob_target) stopifnot(is(Effmodel, "ModelEff")) stopifnot(is(Effsamples, "Samples")) stopifnot(is.function(TDderive)) @@ -3135,7 +3135,7 @@ setMethod("stopTrial", prob_target <- stopping@prob_target ## checks - stopifnot(is.probability(prob_target)) + assert_probability(prob_target) stopifnot(is(Effmodel, "ModelEff")) diff --git a/R/fromQuantiles.R b/R/fromQuantiles.R index 860b8201e..4513b736e 100644 --- a/R/fromQuantiles.R +++ b/R/fromQuantiles.R @@ -76,8 +76,10 @@ Quantiles2LogisticNormal <- function(dosegrid, )) { ## extracts and checks nDoses <- length(dosegrid) + assert_flag(logNormal) assert_flag(verbose) + assert_probability(level, bounds_closed = FALSE) stopifnot( !is.unsorted(dosegrid, strictly = TRUE), ## the medians must be monotonically increasing: @@ -87,7 +89,6 @@ Quantiles2LogisticNormal <- function(dosegrid, identical(length(upper), nDoses), all(lower < median), all(upper > median), - is.probability(level, bounds = FALSE), identical(length(parlower), 5L), identical(length(parupper), 5L), all(parlower < parstart), @@ -234,10 +235,8 @@ Quantiles2LogisticNormal <- function(dosegrid, ##' @export ##' @keywords programming getMinInfBeta <- function(p, q) { - stopifnot( - is.probability(p, bounds = FALSE), - is.probability(q, bounds = FALSE) - ) + assert_probability(p, bounds_closed = FALSE) + assert_probability(q, bounds_closed = FALSE) ret <- if (q > p) { @@ -309,12 +308,13 @@ MinimalInformative <- function(dosegrid, ...) { ## extracts and checks nDoses <- length(dosegrid) + + assert_probability(threshmin, bounds_closed = FALSE) + assert_probability(threshmax, bounds_closed = FALSE) + assert_probability(probmin, bounds_closed = FALSE) + assert_probability(probmax, bounds_closed = FALSE) stopifnot( - !is.unsorted(dosegrid, strictly = TRUE), - is.probability(threshmin, bounds = FALSE), - is.probability(threshmax, bounds = FALSE), - is.probability(probmin, bounds = FALSE), - is.probability(probmax, bounds = FALSE) + !is.unsorted(dosegrid, strictly = TRUE) ) xmin <- dosegrid[1] xmax <- dosegrid[nDoses] diff --git a/R/helpers.R b/R/helpers.R index 2c3e077be..75b933b95 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -127,47 +127,6 @@ safeInteger <- function(x) { as.integer(x) } -##' Predicate checking for a probability -##' -##' @param x the object being checked -##' @param bounds whether to include the bounds 0 and 1 (default) -##' @return Returns \code{TRUE} if \code{x} is a probability -##' -##' @keywords internal -is.probability <- function(x, - bounds = TRUE) { - if (bounds) { - return(test_numeric(x, lower = 0, upper = 1, any.missing = FALSE)) - } else { - return(test_numeric(x, lower = 0, upper = 1, any.missing = FALSE) && x != 0 && x != 1) - } -} - -##' Predicate checking for a numeric range -##' -##' @param x the object being checked -##' @return Returns \code{TRUE} if \code{x} is a numeric range -##' -##' @keywords internal -is.range <- function(x) { - return(identical(length(x), 2L) && - x[1] < x[2]) -} - -##' Predicate checking for a probability range -##' -##' @param x the object being checked -##' @param bounds whether to include the bounds 0 and 1 (default) -##' @return Returns \code{TRUE} if \code{x} is a probability range -##' -##' @keywords internal -is.probRange <- function(x, - bounds = TRUE) { - return(is.range(x) && - all(sapply(x, is.probability, bounds = bounds))) -} - - ##' Shorthand for logit function ##' ##' @param x the function argument diff --git a/man/is.probRange.Rd b/man/is.probRange.Rd deleted file mode 100644 index e27fd5f60..000000000 --- a/man/is.probRange.Rd +++ /dev/null @@ -1,20 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R -\name{is.probRange} -\alias{is.probRange} -\title{Predicate checking for a probability range} -\usage{ -is.probRange(x, bounds = TRUE) -} -\arguments{ -\item{x}{the object being checked} - -\item{bounds}{whether to include the bounds 0 and 1 (default)} -} -\value{ -Returns \code{TRUE} if \code{x} is a probability range -} -\description{ -Predicate checking for a probability range -} -\keyword{internal} diff --git a/man/is.probability.Rd b/man/is.probability.Rd deleted file mode 100644 index c83356096..000000000 --- a/man/is.probability.Rd +++ /dev/null @@ -1,20 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R -\name{is.probability} -\alias{is.probability} -\title{Predicate checking for a probability} -\usage{ -is.probability(x, bounds = TRUE) -} -\arguments{ -\item{x}{the object being checked} - -\item{bounds}{whether to include the bounds 0 and 1 (default)} -} -\value{ -Returns \code{TRUE} if \code{x} is a probability -} -\description{ -Predicate checking for a probability -} -\keyword{internal} diff --git a/man/is.range.Rd b/man/is.range.Rd deleted file mode 100644 index fbcea09d6..000000000 --- a/man/is.range.Rd +++ /dev/null @@ -1,18 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R -\name{is.range} -\alias{is.range} -\title{Predicate checking for a numeric range} -\usage{ -is.range(x) -} -\arguments{ -\item{x}{the object being checked} -} -\value{ -Returns \code{TRUE} if \code{x} is a numeric range -} -\description{ -Predicate checking for a numeric range -} -\keyword{internal}