diff --git a/R/inherits.R b/R/inherits.R index c215fc6e..e7a18b92 100644 --- a/R/inherits.R +++ b/R/inherits.R @@ -10,6 +10,9 @@ #' @returns #' * `S7_inherits()` returns a single `TRUE` or `FALSE`. #' * `check_is_S7()` returns nothing; it's called for its side-effects. +#' +#' @note Starting with \R 4.3.0, `base::inherits()` can accept an S7 class as +#' the second argument, supporting usage like `inherits(x, Foo)`. #' @export #' @examples #' Foo1 <- new_class("Foo1") @@ -21,6 +24,9 @@ #' #' S7_inherits(Foo1(), Foo2) #' try(check_is_S7(Foo1(), Foo2)) +#' +#' if (getRversion() >= "4.3.0") +#' inherits(Foo1(), Foo1) S7_inherits <- function(x, class = NULL) { if (!(is.null(class) || inherits(class, "S7_class"))) { stop("`class` must be an or NULL") diff --git a/man/S7_inherits.Rd b/man/S7_inherits.Rd index ba9bb602..e9206f27 100644 --- a/man/S7_inherits.Rd +++ b/man/S7_inherits.Rd @@ -29,6 +29,10 @@ S7 object without testing for a specific class.} \item \code{check_is_S7()} throws an error if \code{x} isn't the specified \code{class}. } } +\note{ +Starting with \R 4.3.0, \code{base::inherits()} can accept an S7 class as +the second argument, supporting usage like \code{inherits(x, Foo)}. +} \examples{ Foo1 <- new_class("Foo1") Foo2 <- new_class("Foo2") @@ -39,4 +43,7 @@ check_is_S7(Foo1(), Foo1) S7_inherits(Foo1(), Foo2) try(check_is_S7(Foo1(), Foo2)) + +if (getRversion() >= "4.3.0") + inherits(Foo1(), Foo1) }