Skip to content

Commit

Permalink
Use rlang's check_installed() (#1887)
Browse files Browse the repository at this point in the history
  • Loading branch information
hadley committed Oct 30, 2023
1 parent f5c71bb commit 5659da8
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 15 deletions.
2 changes: 1 addition & 1 deletion R/reporter-junit.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions R/snapshot-manage.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion R/test-compiled-code.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
11 changes: 0 additions & 11 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5659da8

Please sign in to comment.