| @@ -709,23 +709,6 @@ register_font <- function( | |||
| family | |||
| } | |||
| requires_package <- function(pkg = "ggplot2", fn = "", required = TRUE) { | |||
| raise <- if (required) stop else warning | |||
| if (!requireNamespace(pkg, quietly = TRUE)) { | |||
| msg <- paste0( | |||
| "`", | |||
| pkg, | |||
| "` is ", | |||
| if (required) "required " else "suggested ", | |||
| if (fn != "") paste0("by ", fn, "() ")[1], | |||
| "but is not installed." | |||
| ) | |||
| raise(msg, call. = FALSE) | |||
| invisible(FALSE) | |||
| } | |||
| invisible(TRUE) | |||
| } | |||
| requires_xaringanthemer_env <- function( | |||
| css_file = NULL, | |||
| try_css = TRUE, | |||
| @@ -74,6 +74,23 @@ is_light_color <- function(x) { | |||
| lum[1, 1] > 0.179 | |||
| } | |||
| requires_package <- function(pkg = "ggplot2", fn = "", required = TRUE) { | |||
| raise <- if (required) stop else warning | |||
| if (!requireNamespace(pkg, quietly = TRUE)) { | |||
| msg <- paste0( | |||
| "`", | |||
| pkg, | |||
| "` is ", | |||
| if (required) "required " else "suggested ", | |||
| if (fn != "") paste0("by ", fn, "() ")[1], | |||
| "but is not installed." | |||
| ) | |||
| raise(msg, call. = FALSE) | |||
| return(invisible(FALSE)) | |||
| } | |||
| invisible(TRUE) | |||
| } | |||
| #' @keywords internal | |||
| call_style_xaringan <- function() { | |||
| paste0( | |||
| @@ -4,3 +4,10 @@ test_that("printing google_font works", { | |||
| "google-font-print.txt" | |||
| ) | |||
| }) | |||
| test_that("requires_package()", { | |||
| expect_true(requires_package("purrr")) | |||
| expect_error(requires_package("notapackage", "myFunction"), "myFunction") | |||
| expect_warning(requires_package("notapackage", required = FALSE)) | |||
| expect_false(requires_package("notapackage", required = FALSE)) | |||
| }) | |||