New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
webr::global_prompt_install()
not working with webR.evalR()
#324
Comments
The |
Ah, thanks! |
Ah, I just saw this part of the question! There's no support for an allow-list, I think you'd have to implement that yourself. You might be able to use |
Hrm: when I run that, I get "WebRWorkerError: should not be called with handlers on the stack". |
Ah yes, there's a gap in documentation here, sorry. To install the new global error handler we have to temporarily turn off webR's other built-in error and warning capturing handlers. Try with:
I'll reopen this to remind me to document it. |
webr::global_prompt_install()
requires withHandlers: false
I've done some experimentation, and I can't seem to get this working with It does seem to work when using const webR = await new WebR();
await webR.init();
await webR.evalRVoid(`webr::global_prompt_install(FALSE)`, { withHandlers: false });
await webR.writeConsole(`library(dplyr)`);
for (;;) {
const output = await webR.read();
switch (output.type) {
case 'stdout':
console.log(output.data)
break;
case 'stderr':
console.log(output.data);
break;
case 'prompt':
console.log(output.data);
break;
default:
console.error(`Unimplemented output type: ${output.type}`);
console.error(output.data);
}
} (https://terrific-coordinated-parrot.glitch.me/) EDIT: yes, this is clearly not working right. Even here two invocations of Probably it's best to stick with your own method around shimming |
webr::global_prompt_install()
requires withHandlers: false
webr::global_prompt_install()
not working with webR.evalR()
For completeness, something like this should allow you to shim const webR = await new WebR();
await webR.init();
await webR.evalRVoid(`
.e <- new.env()
.e[["library"]] <- function (pkg, ...) {
package <- as.character(substitute(pkg))
if (!require(package)) webr::install(package)
base::library(package, character.only = TRUE, ...)
}
attach(.e, name = "library_shim", warn.conflicts = FALSE)
`);
await webR.evalR(`library(dplyr)\nprint(starwars)`); |
The WebR support package has a function
webr::global_prompt_install()
which will interactively prompt you to install a package before loading it.Is there a way of getting WebR to automatically install packages without a prompt? Or could I write my own shim round
library()
to do this?The text was updated successfully, but these errors were encountered: