Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions R/compile_qmd_course.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#' use this option to correctly edit their path.
#' @param render_pdf logical. If TRUE, render a pdf version of the html file
#' @param render_pdf_fun function. Function to use to render the pdf. Default to pagedown::chrome_print. The function need to take a path to a html file as input.
#' @param render_qmd_purrr_insistently_rate_backoff function. Function to use to retry rendering qmd files in case of failure. Should be a purrr::rate_backoff function.
#'
#' @importFrom tools file_ext
#' @importFrom htmltools htmlTemplate renderDocument save_html HTML
Expand Down Expand Up @@ -93,7 +94,11 @@ compile_qmd_course <- function(
debug = FALSE,
fix_img_path = TRUE,
render_pdf = FALSE,
render_pdf_fun = pagedown::chrome_print
render_pdf_fun = pagedown::chrome_print,
render_qmd_purrr_insistently_rate_backoff = purrr::rate_backoff(
pause_base = 0.1,
max_times = 5
)
) {
# check inputs and future settings
not_all_files_are_qmd <- any(
Expand Down Expand Up @@ -157,7 +162,8 @@ compile_qmd_course <- function(
img_root_dir = img_root_dir,
output_format = output_format,
metadata = metadata_qmd,
quiet = !debug
quiet = !debug,
purrr_insistently_rate_backoff = render_qmd_purrr_insistently_rate_backoff
)
},
# make random number generation reproducible
Expand Down
5 changes: 2 additions & 3 deletions R/fetch_future_settings.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#' @noRd
#' @examples
#' fetch_future_settings(vec_qmd_path = qmd, quiet = FALSE)
fetch_future_settings <- function(
quiet = TRUE) {
fetch_future_settings <- function(quiet = TRUE) {
# look for future settings (e.g. parallel, sequential, default)
future_setting <- attr(plan(), "call")
future_setting <- ifelse(
Expand All @@ -20,7 +19,7 @@ fetch_future_settings <- function(
no = deparse(future_setting)
)

if (isFALSE(quiet) && !grepl("default", future_setting)) {
if (isFALSE(quiet) && !grepl("sequential", future_setting)) {
cli_alert_info(paste(
"{{future}} is using {future_setting},",
"to modify this use {.code future::plan()}"
Expand Down
14 changes: 12 additions & 2 deletions R/render_single_qmd.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#' @param qmd character. Path to the qmd file to render
#' @param img_root_dir character. Path to the main image folder to extract media to
#' @param metadata list. List of metadata to be used for rendering single qmd file
#' @param purrr_insistently_rate_backoff function. Function to use to retry rendering qmd files in case of failure. Should be a purrr::rate_backoff function.
#'
#' @inheritParams compile_qmd_course
#'
Expand Down Expand Up @@ -46,7 +47,11 @@ render_single_qmd <- function(
img_root_dir = "img",
output_format = "revealjs",
metadata = NULL,
quiet = TRUE
quiet = TRUE,
purrr_insistently_rate_backoff = purrr::rate_backoff(
pause_base = 0.1,
max_times = 5
)
) {
# set image sub-folder name
chapter <- dirname(qmd)
Expand All @@ -56,10 +61,15 @@ render_single_qmd <- function(
paste0(basename(chapter), "_img")
)

quarto_render_insistently <- purrr::insistently(
quarto_render,
rate = purrr_insistently_rate_backoff
)

# try rendering qmd and warn user if successful / fail
tryCatch(
expr = {
quarto_render(
quarto_render_insistently(
input = qmd,
metadata = c(metadata, list(`extract-media` = img_dir)),
output_format = output_format,
Expand Down
6 changes: 5 additions & 1 deletion man/compile_qmd_course.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/render_single_qmd.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 7 additions & 12 deletions tests/testthat/test-fetch_future_settings.R
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
test_that("future settings does not speak for default behaviour", {
# set to default
plan("default")

test_that("fetch_future_settings quiet TRUE vs FALSE", {
oplan <- plan("default")
on.exit(plan(oplan), add = TRUE)
expect_message(
object = {
fetch_future_settings(quiet = FALSE)
fetch_future_settings(FALSE)
},
regexp = NA
)
})

test_that("future settings does not speak for default behaviour", {
# set a multisession with one worker
plan(future::multisession, workers = 1)

test_that("fetch_future_settings speak when future::multisession", {
oplan <- plan(future::multisession, workers = 1)
on.exit(plan(oplan), add = TRUE)
expect_message(
object = {
fetch_future_settings(quiet = FALSE)
},
regexp = "\\{future\\} is using plan\\(future::multisession, workers = 1\\)"
)

# reset to default
plan("default")
})