diff --git a/NEWS.md b/NEWS.md index 015e838b0..0a1ea665d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,7 @@ * Remove redundant entries in the documentation index when multiple explicit `@usage` tags are provided (@klmr, #2302) * The article index now sorts vignettes and non-vignette articles alphabetically by their filename (literally, their `basename()`), by default (@jennybc, #2253). * Add Catalan translation (@jmaspons, #2333) +* Set RNG seed for htmlwidgets IDs. This reduces noise in pkgdown reference HTML output when examples generate htmlwidgets (@salim-b, #2294). # pkgdown 2.0.7 diff --git a/R/build-reference.R b/R/build-reference.R index ef8c94e53..add462c13 100644 --- a/R/build-reference.R +++ b/R/build-reference.R @@ -139,8 +139,8 @@ #' rapidly prototype. It is set to `FALSE` by [build_site()]. #' @param run_dont_run Run examples that are surrounded in \\dontrun? #' @param examples Run examples? -#' @param seed Seed used to initialize so that random examples are -#' reproducible. +#' @param seed Seed used to initialize random number generation so that +#' examples are reproducible. #' @param devel Determines how code is loaded in order to run examples. #' If `TRUE` (the default), assumes you are in a live development #' environment, and loads source package with [pkgload::load_all()]. @@ -223,6 +223,9 @@ examples_env <- function(pkg, seed = 1014, devel = TRUE, envir = parent.frame()) width <- purrr::pluck(pkg, "meta", "code", "width", .default = 80) withr::local_options(width = width, .local_envir = envir) withr::local_seed(seed) + if (requireNamespace("htmlwidgets", quietly = TRUE)) { + htmlwidgets::setWidgetIdSeed(seed) + } examples_env <- child_env(globalenv()) if (file_exists(pre_path)) { diff --git a/man/build_reference.Rd b/man/build_reference.Rd index 81561844a..730c2e2a3 100644 --- a/man/build_reference.Rd +++ b/man/build_reference.Rd @@ -31,8 +31,8 @@ rapidly prototype. It is set to \code{FALSE} by \code{\link[=build_site]{build_s \item{run_dont_run}{Run examples that are surrounded in \\dontrun?} -\item{seed}{Seed used to initialize so that random examples are -reproducible.} +\item{seed}{Seed used to initialize random number generation so that +examples are reproducible.} \item{override}{An optional named list used to temporarily override values in \verb{_pkgdown.yml}} diff --git a/man/build_site.Rd b/man/build_site.Rd index cb56aedb0..7b5e80af7 100644 --- a/man/build_site.Rd +++ b/man/build_site.Rd @@ -25,8 +25,8 @@ build_site( \item{run_dont_run}{Run examples that are surrounded in \\dontrun?} -\item{seed}{Seed used to initialize so that random examples are -reproducible.} +\item{seed}{Seed used to initialize random number generation so that +examples are reproducible.} \item{lazy}{If \code{TRUE}, will only rebuild articles and reference pages if the source is newer than the destination.} diff --git a/vignettes/test/widgets.Rmd b/vignettes/test/widgets.Rmd index aee369960..f4200cc90 100644 --- a/vignettes/test/widgets.Rmd +++ b/vignettes/test/widgets.Rmd @@ -15,7 +15,7 @@ Test spacing above widget. ```{r, echo=FALSE} # set seed for reproducible widget id -if (requireNamespace("htmltools", quietly = TRUE)) { +if (requireNamespace("htmlwidgets", quietly = TRUE)) { htmlwidgets::setWidgetIdSeed(42) }