Skip to content

Commit

Permalink
Enable install.packages() shim (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
coatless authored Jan 19, 2024
1 parent c9fd938 commit f9d2560
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions _extensions/webr/qwebr-document-engine-initialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/qwebr-release-notes.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 23 additions & 0 deletions tests/qwebr-test-shim-install.qmd
Original file line number Diff line number Diff line change
@@ -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")))
```

0 comments on commit f9d2560

Please sign in to comment.