Skip to content

Commit

Permalink
is_webr(): webr (>= 0.3.2-9000) sets env var 'WEBR' [#133]
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikBengtsson committed Apr 24, 2024
1 parent 664af6f commit 0f2a576
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: startup
Version: 0.21.0-9004
Version: 0.21.0-9005
Title: Friendly R Startup Configuration
Depends: R (>= 2.14.0)
Suggests: commonmark, tools, tcltk
Expand Down
5 changes: 5 additions & 0 deletions R/is_webr.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
#' 1. WebR - R in the Browser, <https://docs.r-wasm.org/webr/latest/>
is_webr <- function() {
if (!"webr" %in% loadedNamespaces()) return(FALSE)

## Source: https://github.com/r-wasm/webr/issues/414
## In webr (> 0.3.2) [2024-04-23]
if (Sys.getenv("WEBR") == "1") return(TRUE)

## Fallback: https://github.com/r-wasm/webr/issues/414
ns <- getNamespace("webr")
if (!exists("eval_js", mode = "function", envir = ns)) return(FALSE)
eval_js <- get("eval_js", mode = "function", envir = ns)
Expand Down

0 comments on commit 0f2a576

Please sign in to comment.