Title: | Build R Packages for WebAssembly |
---|---|
Description: | Utility functions to help build R packages compiled for WebAssembly (Wasm), manage Wasm binary R package libraries and repositories, and prepare webR compatible filesystem images for static web hosting of data files and R packages. |
Authors: | George Stagg [aut, cre], Lionel Henry [ctb], Jeroen Ooms [ctb], Posit Software, PBC [cph, fnd] |
Maintainer: | George Stagg <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.0 |
Built: | 2025-03-22 11:19:43 UTC |
Source: | https://github.com/r-wasm/rwasm |
Downloads and builds the list of R package references
in the file list_file
, compiling each package for use with WebAssembly and
webR. The resulting WebAssembly binary packages are added to the repository
directory repo_dir
. The repository directory will be created if it does not
already exist.
add_list(list_file, ...)
add_list(list_file, ...)
list_file |
Path to a file containing a list of R package references. |
... |
Arguments passed on to
|
The R package references should be listed in the file list_file
, one line
per package reference.
Downloads and builds the R package references given
by packages
, compiling each package for use with WebAssembly and webR. The
resulting WebAssembly binary packages are added to the repository directory
repo_dir
. The repository directory will be created if it does not already
exist.
add_pkg( packages, repo_dir = "./repo", remotes = NA, dependencies = FALSE, compress = TRUE )
add_pkg( packages, repo_dir = "./repo", remotes = NA, dependencies = FALSE, compress = TRUE )
packages |
A character vector of one or more package references. |
repo_dir |
The package repository directory. Defaults to |
remotes |
A character vector of package references to prefer as a remote
source. Defaults to |
dependencies |
Dependency specification for packages to additionally
add to the repository. Defaults to |
compress |
When |
Downloads and builds all available source R packages from the R package
repositories given by repos
, compiling each package for use with
WebAssembly and webR. The resulting WebAssembly binary packages are added to
the repository directory repo_dir
. The repository directory will be created
if it does not already exist.
add_repo(repos = ppm_config$cran_mirror, skip = FALSE, ...)
add_repo(repos = ppm_config$cran_mirror, skip = FALSE, ...)
repos |
A character vector containing the base URL(s) of CRAN-like R package repositories. Defaults to the Posit Package Manager CRAN mirror. |
skip |
A character string containing a regular expression matching names
of packages to skip. Defaults to |
... |
Arguments passed on to
|
tar
archiveCalculates file offsets and other metadata for content stored in an
(optionally gzip compressed) tar
archive. Once added, the tar
archive
with metadata can be mounted as an Emscripten filesystem image, making the
contents of the archive available to the WebAssembly R process.
add_tar_index(file, strip = 0)
add_tar_index(file, strip = 0)
file |
Filename of the |
strip |
Remove the specified number of leading path elements when
mounting with webR. Defaults to |
The virtual filesystem metadata is appended to the end of the tar
archive,
with the output replacing the original file. The resulting archive should be
hosted online so that its URL can be provided to webR for mounting on the
virtual filesystem.
If strip
is greater than 0
the virtual filesystem metadata is generated
such that when mounted by webR the specified number of leading path elements
are removed. Useful for R package binaries where data files are stored in the
original .tgz
file under a subdirectory. Files with fewer path name
elements than the specified amount are skipped.
Downloads and builds the R package references given
by packages
, compiling each package for use with WebAssembly and webR. The
resulting WebAssembly binary packages are written to out_dir
.
build( packages, out_dir = ".", remotes = NULL, dependencies = FALSE, compress = TRUE )
build( packages, out_dir = ".", remotes = NULL, dependencies = FALSE, compress = TRUE )
packages |
A character vector of one or more package references. |
out_dir |
The output directory. Defaults to |
remotes |
A character vector of package references to prefer as a remote
source. If |
dependencies |
Dependency specification for packages to additionally
add to the repository. Defaults to |
compress |
When |
Uses Emscripten's file_packager
tool to build an Emscripten filesystem
image that can be mounted by webR. The filesystem image may contain arbitrary
data that will be made available for use by the WebAssembly R process once
mounted.
file_packager(in_dir, out_dir = "./vfs", out_name = NULL, compress = FALSE)
file_packager(in_dir, out_dir = "./vfs", out_name = NULL, compress = FALSE)
in_dir |
Directory to be packaged into the filesystem image. |
out_dir |
Directory in which to write the output image files. Defaults
to |
out_name |
A character string for the output image base filename. If
|
compress |
Logical. If |
Outputs at least two files (named by out_name
) in the out_dir
directory:
a data file with extension ".data"
, and a metadata file with extension
".js.metadata"
. Both files should be hosted online so that their URL can be
provided to webR for mounting on the Emscripten virtual filesystem.
When compress
is TRUE
, an additional file with extension ".data.gz"
is
also output containing a compressed version of the filesystem data. The
metadata file is also changed to reflect the availability of a compressed
version of the data.
Extracts all R packages contained in the repository directory repo_dir
and
writes them to a library directory lib_dir
.
make_library(repo_dir = "./repo", lib_dir = "./lib", strip = NULL)
make_library(repo_dir = "./repo", lib_dir = "./lib", strip = NULL)
repo_dir |
The package repository directory. Defaults to |
lib_dir |
Package library output directory. Defaults to |
strip |
A character vector of directories to strip from each R package. |
The lib_dir
directory will be created if it does not already exist.
The strip
argument may be used to strip certain directories from packages
installed to the library directory lib_dir
. This can be used to reduce the
total library file size by removing directories that are not strictly
necessary for the R package to run, such as directories containing
documentation and vignettes.
Extracts all binary R packages contained in the repository directory
repo_dir
and creates an Emscripten filesystem image containing the
resulting package library.
make_vfs_library( out_dir = "./vfs", out_name = "library.data", repo_dir = "./repo", compress = FALSE, ... )
make_vfs_library( out_dir = "./vfs", out_name = "library.data", repo_dir = "./repo", compress = FALSE, ... )
out_dir |
Directory in which to write the output image files. Defaults
to |
out_name |
A character string for the output library image filename. |
repo_dir |
The package repository directory. Defaults to |
compress |
When |
... |
Arguments passed on to
|
A single filesystem image is generated using Emscripten's file_packager()
tool and the output .data
and .js.metadata
filesystem image files are
written to the directory out_dir
.
When compress
is TRUE
, an additional file with extension ".data.gz"
is
also output containing a compressed version of the filesystem data.
The resulting image can be downloaded by webR and mounted on the Emscripten virtual filesystem as an efficient way to provide a pre-configured R library, without installing each R package individually.
Creates an Emscripten filesystem image for each R package that exists in the
package repository directory repo_dir
.
make_vfs_repo(repo_dir = "./repo", compress = FALSE)
make_vfs_repo(repo_dir = "./repo", compress = FALSE)
repo_dir |
The package repository directory. Defaults to |
compress |
When |
Each filesystem image is generated using Emscripten's file_packager()
tool
and the output .data
and .js.metadata
filesystem image files are written
to the repository in the same directory as the package binary .tgz
files.
The resulting filesystem images may then be used by webR to download and
install R packages by mounting the .data
images to the Emscripten virtual
filesystem.
When compress
is TRUE
, an additional file with extension ".data.gz"
is
also output containing a compressed version of the filesystem data.
Remove R package(s) from a package repository
rm_pkg(packages, repo_dir = "./repo")
rm_pkg(packages, repo_dir = "./repo")
packages |
A character vector of one or more package names. |
repo_dir |
The package repository directory. Defaults to |
PACKAGES
file for a package repositoryWrite the PACKAGES
file for a package repository
write_packages(repo_dir = "./repo")
write_packages(repo_dir = "./repo")
repo_dir |
The package repository directory. Defaults to |