Преглед на файлове

Set fig.showtext chunk option on package load and error loudly if fig.showtext = FALSE for a chunk with theme_xaringan()

tags/v0.3.0
Garrick Aden-Buie преди 6 години
родител
ревизия
1e6e51422c
променени са 3 файла, в които са добавени 37 реда и са изтрити 1 реда
  1. +16
    -1
      R/ggplot2.R
  2. +4
    -0
      R/utils.R
  3. +17
    -0
      R/zzz.R

+ 16
- 1
R/ggplot2.R Целия файл

"Font '{family}' must be manually registered using `sysfonts::font_add()`." "Font '{family}' must be manually registered using `sysfonts::font_add()`."
) )
} }
warning(msg, call. = FALSE)
warning(str_wrap(msg), call. = FALSE)
} else {
verify_fig_showtext(fn)
} }
} }
xaringanthemer_env[["registered_font_families"]] <- c( xaringanthemer_env[["registered_font_families"]] <- c(
family family
} }


verify_fig_showtext <- function(fn = "theme_xaringan_base") {
if (is.null(knitr::current_input())) return()
# Try to set fig.showtext automatically
if (isTRUE(knitr::opts_current$get("fig.showtext"))) {
return()
}
stop(str_wrap(
"To use ", fn, "() with knitr, you need to set the chunk option ",
"`fig.showtext = TRUE` for this chunk. Or you can set this option ",
"globally with `knitr::opts_chunk$set(fig.showtext = TRUE)`."
))
}

requires_xaringanthemer_env <- function( requires_xaringanthemer_env <- function(
css_file = NULL, css_file = NULL,
try_css = TRUE, try_css = TRUE,

+ 4
- 0
R/utils.R Целия файл

x[has_space & not_quoted] <- paste0("'", x[has_space & not_quoted], "'") x[has_space & not_quoted] <- paste0("'", x[has_space & not_quoted], "'")
paste(x, collapse = ", ") paste(x, collapse = ", ")
} }

str_wrap <- function(...) {
paste(strwrap(paste0(...)), collapse = "\n")
}

+ 17
- 0
R/zzz.R Целия файл

# nocov start
.onLoad <- function(libname, pkgname, ...) {

if ("knitr" %in% loadedNamespaces()) {
knitr::opts_chunk$set(fig.showtext = TRUE)
}

setHook(
packageEvent("knitr", "onLoad"),
function(...) {
knitr::opts_chunk$set(fig.showtext = TRUE)
}
)

invisible()
}
# nocov end

Loading…
Отказ
Запис