-
Notifications
You must be signed in to change notification settings - Fork 75
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
How to infer R is running in WebR? #414
Comments
I think |
There's some information in > R.Version()
$platform
[1] "wasm32-unknown-emscripten"
$arch
[1] "wasm32"
$os
[1] "emscripten"
$system
[1] "wasm32, emscripten"
[...]
> version$os
[1] "emscripten" We usually look for the "emscripten" string. This makes sense to me, Emscripten is like an alternative OS in many ways, and one day if R core supports building for wasm/Emscripten independently from webR your code will still work. Checking for This information should probably be documented somewhere in https://docs.r-wasm.org, I'll tag the issue as such. |
Thanks. Though, strictly speaking, can't there be other alternative Wasm implementation for R showing up in the future that would show the same CLARIFICATION: I'm after detecting when running with WebR specifically. |
Yes, strictly speaking, that is true assuming the implementation also uses Emscripten as their Unix environment. A project compiling R for WASI/WASIX would likely have a different value there. I guess we could possibly tweak
|
Part of the problem is that the WebAssembly R binary itself knows little about the surrounding webR JavaScript/TypeScript environment other than through the supporting Most of webR's functionality is exposed through a JavaScript Thinking about it, I suppose the webR JavaScript environment is more akin to RStudio than an OS or platform detail and so the Perhaps we could add an export to the webR support package to signal in some way that this is webR, and not the CRAN Alternatively, we could just set some environment variables, similar to A hacky check that would work right now could be something like: webr::eval_js("'webr' in Module") which directly checks the JavaScript environment to see if the |
Thanks for clarifying this - this is useful; my understanding how webR works is at best so-and-so right now.
I think
That would definitely work too. The reason why I came to this is that I wanted to add a flag
A hacky check that would work right now could be something like: webr::eval_js("'webr' in Module") That works for my needs. I can do something like: is_webr <- function() {
if (!"webr" %in% loadedNamespaces()) return(FALSE)
ns <- getNamespace("webr")
if (!exists("eval_js", mode = "function", envir = ns)) return(FALSE)
eval_js <- get("eval_js", mode = "function", envir = ns)
eval_js("'webr' in Module") == 1L
} BTW, is 'webR' how you want to refer to it? I've been using WebR thus far, but better to use the official notation. |
Thank you for sharing those other examples -- I think that's enough to convince me that an environment variable is indeed the right way to go. I'll try to get that in before next release.
I use "webR" unless it's at the start of a sentence, in which case I use "WebR". I don't mind how people refer to it, other than that it should never be "WEBR". |
How can one check, programmatically, that we're running R via WebR?
A naive approach would be to use:
but that assumes such a loaded package is WebR, but it could be another package with the same name, including the one on CRAN (Issue #165).
What other evidence can I look for conclude that we're running within WebR? I'm looking for something more robust, but also something that is sustainable. For example, looking for expected R options is not guaranteed. Neither is the attached
webr_sham
environment and its content.The text was updated successfully, but these errors were encountered: