diff --git a/_extensions/webr/qwebr-document-engine-initialization.js b/_extensions/webr/qwebr-document-engine-initialization.js index 58bb0709..cdfa247b 100644 --- a/_extensions/webr/qwebr-document-engine-initialization.js +++ b/_extensions/webr/qwebr-document-engine-initialization.js @@ -61,6 +61,9 @@ globalThis.qwebrInstance = import(qwebrCustomizedWebROptions.baseURL + "webr.mjs // Setup a pager to allow processing help documentation await mainWebR.evalRVoid('webr::pager_install()'); + // Override the existing install.packages() to use webr::install() + await mainWebR.evalRVoid('webr::shim_install()'); + // Check to see if any packages need to be installed if (qwebrSetupRPackages) { // Obtain only a unique list of packages diff --git a/docs/qwebr-release-notes.qmd b/docs/qwebr-release-notes.qmd index 16c5f9ab..87afe0fb 100644 --- a/docs/qwebr-release-notes.qmd +++ b/docs/qwebr-release-notes.qmd @@ -23,6 +23,7 @@ format: ## Changes - Added new CSS IDs governing the webR initialization state. ([#110](https://github.com/coatless/quarto-webr/issues/110)) +- Added shim that overrides `install.packages()` with `webr::install()` through `webr::shim_install()` this requires webR v0.2.2 to be in use. ([#122](https://github.com/coatless/quarto-webr/issues/122)) ## Bugfixes diff --git a/tests/qwebr-test-shim-install.qmd b/tests/qwebr-test-shim-install.qmd new file mode 100644 index 00000000..b855a246 --- /dev/null +++ b/tests/qwebr-test-shim-install.qmd @@ -0,0 +1,23 @@ +--- +title: "Test: Install Packages Shim" +format: html +engine: knitr +filters: + - webr +--- + +## Non-interactive + +```{webr-r} +#| context: output + +check_pkg_installed <- function(x) { + x %in% installed.packages()[,"Package"] +} + +print(paste0("(Pre-install) Is the package visualize installed? ", check_pkg_installed("visualize"))) + +install.packages("visualize") + +print(paste0("(Post-install) Is the package visualize installed? ", check_pkg_installed("visualize"))) +```