Sfoglia il codice sorgente

Move requires_package to r/utils.R and add tests

tags/v0.3.0
Garrick Aden-Buie 6 anni fa
parent
commit
2aecc9fc10
3 ha cambiato i file con 24 aggiunte e 17 eliminazioni
  1. +0
    -17
      R/ggplot2.R
  2. +17
    -0
      R/utils.R
  3. +7
    -0
      tests/testthat/test-utils.R

+ 0
- 17
R/ggplot2.R Vedi File

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,

+ 17
- 0
R/utils.R Vedi File

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(

+ 7
- 0
tests/testthat/test-utils.R Vedi File

"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))
})

Loading…
Annulla
Salva