From 6a0fb7e4cdfeeae869b6c7b2744283c513eb852f Mon Sep 17 00:00:00 2001 From: colin Date: Tue, 22 Apr 2025 14:16:46 +0200 Subject: [PATCH 1/5] feat: retry the quarto rendering with purrr::insistently --- R/render_single_qmd.R | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/R/render_single_qmd.R b/R/render_single_qmd.R index bb31764..8717f1e 100644 --- a/R/render_single_qmd.R +++ b/R/render_single_qmd.R @@ -56,10 +56,18 @@ render_single_qmd <- function( paste0(basename(chapter), "_img") ) + quarto_render_insistently <- purrr::insistently( + quarto_render, + rates = purrr::rate_backoff( + pause_base = 0.1, + max_times = 5 + ) + ) + # 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, From 1a743dab8d6f45834bd7371e076d6d37e7df1acc Mon Sep 17 00:00:00 2001 From: colin Date: Tue, 22 Apr 2025 14:23:40 +0200 Subject: [PATCH 2/5] fix: rule number 1 --- R/render_single_qmd.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/render_single_qmd.R b/R/render_single_qmd.R index 8717f1e..136b56f 100644 --- a/R/render_single_qmd.R +++ b/R/render_single_qmd.R @@ -58,7 +58,7 @@ render_single_qmd <- function( quarto_render_insistently <- purrr::insistently( quarto_render, - rates = purrr::rate_backoff( + rate = purrr::rate_backoff( pause_base = 0.1, max_times = 5 ) From 1acbc0f3977cef092d1b1c370663054119f75854 Mon Sep 17 00:00:00 2001 From: colin Date: Tue, 22 Apr 2025 15:05:01 +0200 Subject: [PATCH 3/5] feat: pass param for insistently --- R/compile_qmd_course.R | 10 ++++++++-- R/render_single_qmd.R | 12 +++++++----- man/compile_qmd_course.Rd | 6 +++++- man/render_single_qmd.Rd | 5 ++++- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/R/compile_qmd_course.R b/R/compile_qmd_course.R index c017874..2b74729 100644 --- a/R/compile_qmd_course.R +++ b/R/compile_qmd_course.R @@ -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 @@ -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( @@ -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 diff --git a/R/render_single_qmd.R b/R/render_single_qmd.R index 136b56f..7f947ca 100644 --- a/R/render_single_qmd.R +++ b/R/render_single_qmd.R @@ -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 #' @@ -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) @@ -58,10 +63,7 @@ render_single_qmd <- function( quarto_render_insistently <- purrr::insistently( quarto_render, - rate = purrr::rate_backoff( - pause_base = 0.1, - max_times = 5 - ) + rate = purrr_insistently_rate_backoff ) # try rendering qmd and warn user if successful / fail diff --git a/man/compile_qmd_course.Rd b/man/compile_qmd_course.Rd index de40fe3..16e1874 100644 --- a/man/compile_qmd_course.Rd +++ b/man/compile_qmd_course.Rd @@ -19,7 +19,9 @@ compile_qmd_course( 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) ) } \arguments{ @@ -55,6 +57,8 @@ use this option to correctly edit their path.} \item{render_pdf}{logical. If TRUE, render a pdf version of the html file} \item{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.} + +\item{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.} } \value{ character. The path to the resulting html file diff --git a/man/render_single_qmd.Rd b/man/render_single_qmd.Rd index c7c0154..1d17d00 100644 --- a/man/render_single_qmd.Rd +++ b/man/render_single_qmd.Rd @@ -9,7 +9,8 @@ render_single_qmd( 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) ) } \arguments{ @@ -22,6 +23,8 @@ render_single_qmd( \item{metadata}{list. List of metadata to be used for rendering single qmd file} \item{quiet}{logical. Output info in user console} + +\item{purrr_insistently_rate_backoff}{function. Function to use to retry rendering qmd files in case of failure. Should be a purrr::rate_backoff function.} } \value{ logical. TRUE if rendering succeeded, FALSE otherwise. Side effect : render qmd as html From 5c16c7fb7faf346ead0cccc083c9fccf1acf5d20 Mon Sep 17 00:00:00 2001 From: colin Date: Tue, 22 Apr 2025 16:09:22 +0200 Subject: [PATCH 4/5] fix: future settings are by default sequential --- R/fetch_future_settings.R | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/R/fetch_future_settings.R b/R/fetch_future_settings.R index 4db58fd..6ee6621 100644 --- a/R/fetch_future_settings.R +++ b/R/fetch_future_settings.R @@ -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( @@ -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()}" From 4b41a3b5f197b6e1796d1bb603f72f67e2a3fc3b Mon Sep 17 00:00:00 2001 From: colin Date: Tue, 22 Apr 2025 16:11:20 +0200 Subject: [PATCH 5/5] test: fixing the tests for fetch_future_settings --- tests/testthat/test-fetch_future_settings.R | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/tests/testthat/test-fetch_future_settings.R b/tests/testthat/test-fetch_future_settings.R index 8f47039..8933a08 100644 --- a/tests/testthat/test-fetch_future_settings.R +++ b/tests/testthat/test-fetch_future_settings.R @@ -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") })