From 81c3655f2d230589acdafc4a0d4aeb2ac66ca02c Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Wed, 6 Nov 2024 11:20:57 -0600 Subject: [PATCH] Updates for `expect_vector()` (#2018) * Check that {vctrs} is installed. * Remove version check from examples * Use `@examplesIf` --- R/expect-vector.R | 5 ++--- man/expect_vector.Rd | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/R/expect-vector.R b/R/expect-vector.R index a972ef43f..e62da16e8 100644 --- a/R/expect-vector.R +++ b/R/expect-vector.R @@ -10,13 +10,12 @@ #' size-0 (empty) generalised vector. #' @param size (Optional) Size to check for. #' @export -#' @examples -#' if (requireNamespace("vctrs") && packageVersion("vctrs") > "0.1.0.9002") { +#' @examplesIf requireNamespace("vctrs") #' expect_vector(1:10, ptype = integer(), size = 10) #' show_failure(expect_vector(1:10, ptype = integer(), size = 5)) #' show_failure(expect_vector(1:10, ptype = character(), size = 5)) -#' } expect_vector <- function(object, ptype = NULL, size = NULL) { + check_installed("vctrs") act <- quasi_label(enquo(object), arg = "object") message <- NULL diff --git a/man/expect_vector.Rd b/man/expect_vector.Rd index 6f4b67fc0..cf44af85f 100644 --- a/man/expect_vector.Rd +++ b/man/expect_vector.Rd @@ -24,9 +24,9 @@ means that it used the vctrs of \code{ptype} (prototype) and \code{size}. See details in \url{https://vctrs.r-lib.org/articles/type-size.html} } \examples{ -if (requireNamespace("vctrs") && packageVersion("vctrs") > "0.1.0.9002") { +\dontshow{if (requireNamespace("vctrs")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} expect_vector(1:10, ptype = integer(), size = 10) show_failure(expect_vector(1:10, ptype = integer(), size = 5)) show_failure(expect_vector(1:10, ptype = character(), size = 5)) -} +\dontshow{\}) # examplesIf} }