| family | 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( | requires_xaringanthemer_env <- function( | ||||
| css_file = NULL, | css_file = NULL, | ||||
| try_css = TRUE, | try_css = TRUE, |
| lum[1, 1] > 0.179 | 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 | #' @keywords internal | ||||
| call_style_xaringan <- function() { | call_style_xaringan <- function() { | ||||
| paste0( | paste0( |
| "google-font-print.txt" | "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)) | |||||
| }) |