From c7210b3a8789b131bbb65a3671c69ef1e1a3f5c0 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Mon, 23 Oct 2023 14:19:45 -0500 Subject: [PATCH] Use rlang's check_installed() --- R/reporter-junit.R | 2 +- R/snapshot-manage.R | 3 +-- R/test-compiled-code.R | 2 +- R/utils.R | 11 ----------- 4 files changed, 3 insertions(+), 15 deletions(-) diff --git a/R/reporter-junit.R b/R/reporter-junit.R index 28952595e..f9cdb75b8 100644 --- a/R/reporter-junit.R +++ b/R/reporter-junit.R @@ -56,7 +56,7 @@ JunitReporter <- R6::R6Class("JunitReporter", }, start_reporter = function() { - check_installed("xml2", "JunitReporter") + check_installed("xml2", "to use JunitReporter") self$timer <- private$proctime() self$doc <- xml2::xml_new_document() diff --git a/R/snapshot-manage.R b/R/snapshot-manage.R index 92cfbc77d..afd1cbc29 100644 --- a/R/snapshot-manage.R +++ b/R/snapshot-manage.R @@ -29,8 +29,7 @@ snapshot_accept <- function(files = NULL, path = "tests/testthat") { #' @rdname snapshot_accept #' @export snapshot_review <- function(files = NULL, path = "tests/testthat") { - check_installed("shiny", "snapshot_review()") - check_installed("diffviewer", "snapshot_review()") + check_installed(c("shiny", "diffviewer"), "to use snapshot_review()") changed <- snapshot_meta(files, path) if (nrow(changed) == 0) { diff --git a/R/test-compiled-code.R b/R/test-compiled-code.R index f0be3b8e9..46f1350d8 100644 --- a/R/test-compiled-code.R +++ b/R/test-compiled-code.R @@ -32,7 +32,7 @@ expect_cpp_tests_pass <- function(package) { #' @export run_cpp_tests <- function(package) { skip_on_os("solaris") - check_installed("xml2", "run_cpp_tests()") + check_installed("xml2", "to run run_cpp_tests()") run_testthat_tests <- get_routine(package, "run_testthat_tests") diff --git a/R/utils.R b/R/utils.R index 03f13c012..691541d2c 100644 --- a/R/utils.R +++ b/R/utils.R @@ -81,17 +81,6 @@ rstudio_tickle <- function() { rstudioapi::executeCommand("refreshFiles") } -check_installed <- function(pkg, fun) { - if (is_installed(pkg)) { - return() - } - - abort(c( - paste0("The ", pkg, " package must be installed in order to use `", fun, "`"), - i = paste0("Do you need to run `install.packages('", pkg, "')`?") - )) -} - first_upper <- function(x) { substr(x, 1, 1) <- toupper(substr(x, 1, 1)) x