diff --git a/R/expect-inheritance.R b/R/expect-inheritance.R index 58dd72b84..3238fcdc7 100644 --- a/R/expect-inheritance.R +++ b/R/expect-inheritance.R @@ -20,16 +20,17 @@ #' See [expect_vector()] for testing properties of objects created by vctrs. #' #' @param type String giving base type (as returned by [typeof()]). -#' @param class -#' * `expect_type()`: a single string giving an R base type. -#' * `expect_s3_class()`: a character vector of class names or `NA` to assert -#' that `object` isn't an S3 object. If you provide multiple class names, -#' the test will pass if `object` inherits from any of them, unless -#' `exact = TRUE`. -#' * `expect_s4_class()`: a character vector of class names or `NA` to assert -#' that `object` isn't an S4 object. -#' * `expect_r6_class()`: a string. -#' * `expect_s7_class()`: an [S7::S7_class()] object. +#' @param class The required type varies depending on the function: +#' * `expect_type()`: a string. +#' * `expect_s3_class()`: a string or character vector. The behaviour of +#' multiple values (i.e. a character vector) is controlled by the +#' `exact` argument. +#' * `expect_s4_class()`: a string. +#' * `expect_r6_class()`: a string. +#' * `expect_s7_class()`: an [S7::S7_class()] object. +#' +#' For historical reasons, `expect_s3_class()` and `expect_s4_class()` also +#' take `NA` to assert that the `object` is not an S3 or S4 object. #' @inheritParams expect_that #' @family expectations #' @examples @@ -85,7 +86,7 @@ expect_type <- function(object, type) { #' @rdname inheritance-expectations #' @param exact If `FALSE`, the default, checks that `object` inherits #' from any element of `class`. If `TRUE`, checks that object has a class -#' that's identical to `class`. +#' that exactly matches `class`. expect_s3_class <- function(object, class, exact = FALSE) { check_bool(exact) diff --git a/man/inheritance-expectations.Rd b/man/inheritance-expectations.Rd index 5d678b9d9..41ae792de 100644 --- a/man/inheritance-expectations.Rd +++ b/man/inheritance-expectations.Rd @@ -28,21 +28,23 @@ within a function or for loop. See \link{quasi_label} for more details.} \item{type}{String giving base type (as returned by \code{\link[=typeof]{typeof()}}).} -\item{class}{\itemize{ -\item \code{expect_type()}: a single string giving an R base type. -\item \code{expect_s3_class()}: a character vector of class names or \code{NA} to assert -that \code{object} isn't an S3 object. If you provide multiple class names, -the test will pass if \code{object} inherits from any of them, unless -\code{exact = TRUE}. -\item \code{expect_s4_class()}: a character vector of class names or \code{NA} to assert -that \code{object} isn't an S4 object. +\item{class}{The required type varies depending on the function: +\itemize{ +\item \code{expect_type()}: a string. +\item \code{expect_s3_class()}: a string or character vector. The behaviour of +multiple values (i.e. a character vector) is controlled by the +\code{exact} argument. +\item \code{expect_s4_class()}: a string. \item \code{expect_r6_class()}: a string. \item \code{expect_s7_class()}: an \code{\link[S7:S7_class]{S7::S7_class()}} object. -}} +} + +For historical reasons, \code{expect_s3_class()} and \code{expect_s4_class()} also +take \code{NA} to assert that the \code{object} is not an S3 or S4 object.} \item{exact}{If \code{FALSE}, the default, checks that \code{object} inherits from any element of \code{class}. If \code{TRUE}, checks that object has a class -that's identical to \code{class}.} +that exactly matches \code{class}.} } \description{ See \url{https://adv-r.hadley.nz/oo.html} for an overview of R's OO systems, and