Skip to contents

Builds a self-contained webR site in dest with the webR engine, the requested packages with their dependencies (or whole repositories), a package index so install.packages() works with no network, the viewer, a _headers file and a LICENSES/ directory. Everything is downloaded at build time and checked against the repositories' checksums, and nothing is fetched when the page runs.

Usage

collection_mirror(
  dest,
  packages = NULL,
  mode = c("packages", "full"),
  share_links = "off",
  webr_version = NULL,
  repos = NULL,
  favicon = NULL
)

Arguments

dest

Directory to build the mirror in, created if needed. Package files already there whose checksum matches are reused, so an interrupted mirror resumes when the same call is run again.

packages

Character vector of packages for mode = "packages". NULL builds an empty REPL (with an empty package index).

mode

"packages" (the default) mirrors packages and their dependencies, and "full" mirrors every package of every repository (tens of GB).

What a share link may do on the mirror, which is "off" (the default, where links are ignored and the Share button is hidden), "fixed" (links may add files only) or "open" (links may also add packages, which the mirror can install only if they are in its repository).

webr_version

webR version. NULL uses the WEBRARIAN_WEBR_VERSION environment variable, else the newest version tested with this webrarian.

repos

Extra WebAssembly package repositories, searched after repo.r-wasm.org (an r-universe, for example).

favicon

Path to an icon (svg, ico or png) for the mirror's page. NULL uses a built-in default icon.

Value

Invisibly, dest.

Examples

# Downloads the ~40 MB webR engine and the packages. Run only in an
# interactive session with a network connection, so R CMD check never makes
# this download (--as-cran runs the "donttest" examples too). The download
# cache goes under tempdir() here.
if (interactive() && requireNamespace("curl", quietly = TRUE) &&
    curl::has_internet()) {
  old <- Sys.getenv("R_USER_CACHE_DIR", unset = NA)
  Sys.setenv(R_USER_CACHE_DIR = file.path(tempdir(), "webrarian-cache"))
  mirror <- file.path(tempdir(), "webr-mirror")
  collection_mirror(mirror, packages = "cli")
  list.files(mirror)
  unlink(mirror, recursive = TRUE)
  if (is.na(old)) Sys.unsetenv("R_USER_CACHE_DIR") else Sys.setenv(R_USER_CACHE_DIR = old)
}

if (FALSE) { # \dontrun{
# Every package of repo.r-wasm.org and an r-universe: tens of GB
collection_mirror("/srv/webr-mirror", mode = "full",
                  repos = "https://user.r-universe.dev")
} # }