Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

683 replace/remove is.probability/is.range/is.prob range with applicable additional checkmate assertions #692

Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions R/Rules-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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"))


Expand Down
20 changes: 10 additions & 10 deletions R/fromQuantiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -87,7 +89,6 @@ Quantiles2LogisticNormal <- function(dosegrid,
identical(length(upper), nDoses),
all(lower < median),
all(upper > median),
is.probability(level, bounds = FALSE),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

also here used assert_probability and avoid stopifnot.

identical(length(parlower), 5L),
identical(length(parupper), 5L),
all(parlower < parstart),
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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]
Expand Down
41 changes: 0 additions & 41 deletions R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 0 additions & 20 deletions man/is.probRange.Rd

This file was deleted.

20 changes: 0 additions & 20 deletions man/is.probability.Rd

This file was deleted.

18 changes: 0 additions & 18 deletions man/is.range.Rd

This file was deleted.