From 799330f12165c31b09ae3b96fd92d576967ae523 Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Mon, 3 Jun 2024 08:31:27 +0200 Subject: [PATCH] 94 helpers.r (#95) Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com> --- DESCRIPTION | 2 +- NAMESPACE | 1 - R/helpers.R | 77 ----------------------------------- man/is.bool.Rd | 19 --------- man/is.probRange.Rd | 20 --------- man/is.probability.Rd | 20 --------- man/is.scalar.Rd | 19 --------- man/logit.Rd | 23 ----------- tests/testthat/test-helpers.R | 13 ------ 9 files changed, 1 insertion(+), 193 deletions(-) delete mode 100644 R/helpers.R delete mode 100644 man/is.bool.Rd delete mode 100644 man/is.probRange.Rd delete mode 100644 man/is.probability.Rd delete mode 100644 man/is.scalar.Rd delete mode 100644 man/logit.Rd delete mode 100644 tests/testthat/test-helpers.R diff --git a/DESCRIPTION b/DESCRIPTION index fc6e28a2..cbeab397 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,6 +22,7 @@ BugReports: https://github.com/genentech/phase1b/issues Depends: R (>= 3.6) Suggests: + rmarkdown, bookdown, knitr, officer, @@ -54,7 +55,6 @@ Collate: 'boundsPredprob.R' 'data.R' 'dbetabinom.R' - 'helpers.R' 'oc2.R' 'oc3.R' 'ocPostprob.R' diff --git a/NAMESPACE b/NAMESPACE index 3af942e9..9b572e48 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,7 +6,6 @@ export(dbetaMix) export(dbetabinom) export(dbetabinomMix) export(dbetadiff) -export(logit) export(myPlot) export(myPlotDiff) export(oc2) diff --git a/R/helpers.R b/R/helpers.R deleted file mode 100644 index 5b7b9c41..00000000 --- a/R/helpers.R +++ /dev/null @@ -1,77 +0,0 @@ -#' -#' Checking for scalar -#' -#' @param x the input -#' @return Returns \code{TRUE} if \code{x} is a length one vector -#' (i.e., a scalar) -#' -#' @keywords internal -is.scalar <- function(x) { - return(identical(length(x), 1L)) -} - - -#' Predicate checking for a boolean option -#' -#' @param x the object being checked -#' @return Returns \code{TRUE} if \code{x} is a length one logical vector (i.e., a -#' scalar) -#' -#' @keywords internal -is.bool <- function(x) { - return(is.scalar(x) && is.logical(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) { - return(is.scalar(x) && - if (bounds) { - 0 <= x && 1 >= x - } else { - 0 < x && 1 > x - }) -} - -#' 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(identical(length(x), 2L) && - x[1] < x[2] && - if (bounds) { - 0 <= x[1] && 1 >= x[2] - } else { - 0 < x[1] && 1 > x[2] - }) -} - - -#' The Logit Function -#' -#' @description `r lifecycle::badge("experimental")` -#' -#' This just calculates the logit. -#' -#' @typed x: numeric -#' probabilities to transform. -#' @return The logit of `x`. -#' -#' @example examples/logit.R -#' @export -logit <- function(x) { - assert_numeric(x, lower = 0, upper = 1, finite = TRUE) - - stats::qlogis(x) -} diff --git a/man/is.bool.Rd b/man/is.bool.Rd deleted file mode 100644 index 23ff5261..00000000 --- a/man/is.bool.Rd +++ /dev/null @@ -1,19 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R -\name{is.bool} -\alias{is.bool} -\title{Predicate checking for a boolean option} -\usage{ -is.bool(x) -} -\arguments{ -\item{x}{the object being checked} -} -\value{ -Returns \code{TRUE} if \code{x} is a length one logical vector (i.e., a -scalar) -} -\description{ -Predicate checking for a boolean option -} -\keyword{internal} diff --git a/man/is.probRange.Rd b/man/is.probRange.Rd deleted file mode 100644 index e27fd5f6..00000000 --- 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 c8335609..00000000 --- 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.scalar.Rd b/man/is.scalar.Rd deleted file mode 100644 index e8735c12..00000000 --- a/man/is.scalar.Rd +++ /dev/null @@ -1,19 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R -\name{is.scalar} -\alias{is.scalar} -\title{Checking for scalar} -\usage{ -is.scalar(x) -} -\arguments{ -\item{x}{the input} -} -\value{ -Returns \code{TRUE} if \code{x} is a length one vector -(i.e., a scalar) -} -\description{ -Checking for scalar -} -\keyword{internal} diff --git a/man/logit.Rd b/man/logit.Rd deleted file mode 100644 index 3eb2ad42..00000000 --- a/man/logit.Rd +++ /dev/null @@ -1,23 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/helpers.R -\name{logit} -\alias{logit} -\title{The Logit Function} -\usage{ -logit(x) -} -\arguments{ -\item{x}{(\code{numeric}):\cr probabilities to transform.} -} -\value{ -The logit of \code{x}. -} -\description{ -\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}} - -This just calculates the logit. -} -\examples{ -x <- seq(0.1, 0.9, 0.1) -logit(x) -} diff --git a/tests/testthat/test-helpers.R b/tests/testthat/test-helpers.R deleted file mode 100644 index 332acd98..00000000 --- a/tests/testthat/test-helpers.R +++ /dev/null @@ -1,13 +0,0 @@ -test_that("logit works as expected", { - probs <- seq(0, 1, length = 100) - result <- logit(probs) - expect_numeric(result, len = length(probs), sorted = TRUE, unique = TRUE) - expect_identical(result[1], -Inf) - expect_identical(result[100], Inf) -}) - -test_that("logit gives expected value for example value 0.2", { - result <- logit(0.2) - expected <- -1.386294 - expect_equal(result, expected, tolerance = 1e-4) -})