From 2275b83c80377238620c21894be10318d9015a46 Mon Sep 17 00:00:00 2001 From: Carson Date: Tue, 21 Apr 2026 17:45:20 -0500 Subject: [PATCH 1/4] Move rmarkdown from Imports to Suggests rmarkdown is only needed for the selfcontained=TRUE path in saveWidget(). Guard the pandoc helper functions with a runtime check so users who never need self-contained output don't need rmarkdown installed. Closes #455 Co-Authored-By: Claude Opus 4.6 --- DESCRIPTION | 3 ++- R/pandoc.R | 7 ++++++- tests/testthat/test-savewidget.R | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 tests/testthat/test-savewidget.R diff --git a/DESCRIPTION b/DESCRIPTION index 6e714fe..15c8ab2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -24,9 +24,10 @@ Imports: htmltools (>= 0.5.7), jsonlite (>= 0.9.16), knitr (>= 1.8), - rmarkdown, + rlang, yaml Suggests: + rmarkdown, testthat Enhances: shiny (>= 1.1) diff --git a/R/pandoc.R b/R/pandoc.R index 16b236d..2422580 100644 --- a/R/pandoc.R +++ b/R/pandoc.R @@ -1,4 +1,8 @@ -write_md_for_pandoc <- function(html, file, background = "white", title, libdir = "lib", use_raw_attr = rmarkdown::pandoc_available("2.0")) { +write_md_for_pandoc <- function(html, file, background = "white", title, libdir = "lib", use_raw_attr = NULL) { + rlang::check_installed("rmarkdown") + if (is.null(use_raw_attr)) { + use_raw_attr <- rmarkdown::pandoc_available("2.0") + } # Forked from htmltools::save_html to work better with pandoc_self_contained_html # ensure that the paths to dependencies are relative to the base @@ -60,6 +64,7 @@ write_md_for_pandoc <- function(html, file, background = "white", title, libdir # The input should be the path to a file that was created using pandoc_save_markdown pandoc_self_contained_html <- function(input, output) { + rlang::check_installed("rmarkdown") if (!rmarkdown::pandoc_available()) { stop( "Saving a widget with selfcontained = TRUE requires pandoc. ", diff --git a/tests/testthat/test-savewidget.R b/tests/testthat/test-savewidget.R new file mode 100644 index 0000000..7fd89f4 --- /dev/null +++ b/tests/testthat/test-savewidget.R @@ -0,0 +1,21 @@ +test_that("pandoc_self_contained_html() errors if rmarkdown is not installed", { + local_mocked_bindings( + check_installed = function(pkg, ...) stop(sprintf("Package '%s' is required.", pkg)), + .package = "rlang" + ) + expect_error( + pandoc_self_contained_html("input.html", "output.html"), + "rmarkdown" + ) +}) + +test_that("write_md_for_pandoc() errors if rmarkdown is not installed", { + local_mocked_bindings( + check_installed = function(pkg, ...) stop(sprintf("Package '%s' is required.", pkg)), + .package = "rlang" + ) + expect_error( + write_md_for_pandoc(htmltools::div("test"), file = tempfile(), title = "test"), + "rmarkdown" + ) +}) From abc18bc1dab02edf9513a70bc7fcbf346c2e81d7 Mon Sep 17 00:00:00 2001 From: Carson Date: Tue, 21 Apr 2026 18:11:51 -0500 Subject: [PATCH 2/4] Add NEWS entry for rmarkdown move to Suggests Co-Authored-By: Claude Opus 4.6 --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index c7da2b7..8176f72 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # htmlwidgets (development version) +* Moved `{rmarkdown}` from `Imports` to `Suggests`. It's now only required when calling `saveWidget(selfcontained = TRUE)`. (#455) + * htmlwidgets hex sticker added * Static widget resize detection now uses `ResizeObserver` instead of `window.resize`, Bootstrap tab/collapse, and ioslides event listeners. This enables widgets to detect container-level size changes (e.g., CSS-driven resizing, sidebar toggles, flexbox/grid layout changes) that were previously missed. (#496) From 31fa821b2df86efa2a46a3fd5d9c19402fdef75f Mon Sep 17 00:00:00 2001 From: Carson Date: Tue, 21 Apr 2026 18:13:15 -0500 Subject: [PATCH 3/4] Remove savewidget tests that only tested mock behavior Co-Authored-By: Claude Opus 4.6 --- tests/testthat/test-savewidget.R | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 tests/testthat/test-savewidget.R diff --git a/tests/testthat/test-savewidget.R b/tests/testthat/test-savewidget.R deleted file mode 100644 index 7fd89f4..0000000 --- a/tests/testthat/test-savewidget.R +++ /dev/null @@ -1,21 +0,0 @@ -test_that("pandoc_self_contained_html() errors if rmarkdown is not installed", { - local_mocked_bindings( - check_installed = function(pkg, ...) stop(sprintf("Package '%s' is required.", pkg)), - .package = "rlang" - ) - expect_error( - pandoc_self_contained_html("input.html", "output.html"), - "rmarkdown" - ) -}) - -test_that("write_md_for_pandoc() errors if rmarkdown is not installed", { - local_mocked_bindings( - check_installed = function(pkg, ...) stop(sprintf("Package '%s' is required.", pkg)), - .package = "rlang" - ) - expect_error( - write_md_for_pandoc(htmltools::div("test"), file = tempfile(), title = "test"), - "rmarkdown" - ) -}) From cc8d25d5d9eb0a597417474230a02852cdc8b572 Mon Sep 17 00:00:00 2001 From: Carson Date: Wed, 22 Apr 2026 10:05:51 -0500 Subject: [PATCH 4/4] Address PR feedback: add rlang minimum version and guard test Add minimum version constraint (>= 1.0.0) for rlang to ensure check_installed() is available. Guard test-pandoc.R against missing rmarkdown with skip_if_not_installed(). Co-Authored-By: Claude Opus 4.6 --- DESCRIPTION | 2 +- tests/testthat/test-pandoc.R | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 15c8ab2..4705ddb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -24,7 +24,7 @@ Imports: htmltools (>= 0.5.7), jsonlite (>= 0.9.16), knitr (>= 1.8), - rlang, + rlang (>= 1.0.0), yaml Suggests: rmarkdown, diff --git a/tests/testthat/test-pandoc.R b/tests/testthat/test-pandoc.R index 3b00b92..cbad8a9 100644 --- a/tests/testthat/test-pandoc.R +++ b/tests/testthat/test-pandoc.R @@ -1,4 +1,5 @@ test_that("Fix for issue #358 works", { + skip_if_not_installed("rmarkdown") skip_if_not( rmarkdown::pandoc_available(), "Test requires pandoc to be installed"