webR 0.3.0
New features
-
Updated to R version 4.3.3.
-
Support for building webR and LLVM Flang as Nix packages, using Nix flakes.
-
WebR's
./configure
script now detects the presence of aEMFC
environment variable in the user's environment. If this variable points to an existingflang-new
binary, and a Fortran runtime library for WebAssembly can also be found, webR will skip building LLVM flang and instead use the version provided by the environment. -
Additional optional Wasm system libraries for linking with R packages: libsodium (#333), webp (#334), imagemagick (#336), libarchive; lz4; zstd (#337), gmp; mpfr; glpk (#339), gsl (#340), libgit2 (#342).
-
The webR development Docker container now contains a Rust toolchain configured to produce binaries for the
wasm32-unknown-emscripten
target, enabling the building of R packages containing Rust code for webR. -
The
webr::canvas()
graphics device has a new argumentcapture
, defaulting toFALSE
. WhenTRUE
, plots are captured into a canvas cache on the webR worker thread. The cache may be accessed from JavaScript throughModule.webr.canvas
. Entries in the canvas cache are destroyed usingwebr::canvas_purge()
orwebr::canvas_destroy(id)
. In this way, thecaptureR()
method now captures plots by default (see below). -
The
RCall
andRFunction
classes now have acapture(options, ...args)
method that captures output during evaluation. -
Errors re-thrown by
evalR
now include information about the source R call, helping to identify the original location of the error. -
JavaScript objects of type
TypedArray
,ArrayBuffer
, andArrayBufferView
(e.g.Uint8Array
) may now be used with theRRaw
R object constructor. The genericRObject
constructor now converts objects of this type to R raw atomic vectors by default. -
Constructing new R objects using
await new RObject(...)
now supports input objects of the form:{a: [...], b: [...]}
or D3-style data arrays of the form:[{a: ..., b: ...}, {a: ..., b: ...}, {a: ..., b: ...}, ... ]
. Where possible, lists are constructed of classdata.frame
. Direct construction withRList()
does not create adata.frame
. -
R
data.frame
objects may be converted into D3-style data arrays using the new R list object method.toD3()
.
Breaking changes
-
The
captureR()
method now captures plots generated by the canvas graphics device by default. Captured plots are returned as an array ofImageBitmap
objects in the propertyimages
. The previous behaviour may be restored either by manually starting a non-capturingwebr::canvas()
device during execution, or by includingcaptureGraphics: false
as part of theoptions
argument. The default options forevalR()
are set so that plotting is not captured, retaining the current behaviour. -
Upgraded the base LLVM distribution from LLVM 14 to LLVM 18, rebasing our Fortran for WebAssembly patches on the latest release of LLVM at time of writing (v18.1.1). The LLVM Fortran compiler binary name is now
flang-new
and webR's build scripts have been updated to reflect this. Theemfc
wrapper script is no longer required, but for the moment the Make variable pointing to theflang-new
compiler is still namedEMFC
for backwards compatibility. -
The LLVM flang build scripts are now sourced using a git submodule, to simplify management of CI builds. The build scripts are available at https://github.com/r-wasm/flang-wasm and the patched LLVM source at https://github.com/r-wasm/llvm-project. This allows for an independent build of the patched LLVM flang for WebAssembly, including as a separate Nix package.
-
shim_install()
now shims base Rlibrary()
andrequire()
commands so that webR packages are downloaded automatically with an optional menu. This extends the functionality of the global package-not-found handler so that the same feature can be used when usingevalR()
(#324). The new shims also ensure thatlibrary()
andrequire()
do not need to be called again once the package is downloaded and available. -
It is no longer assumed that an interactive R session will be able to show a
menu()
when offering to download a missing R package. Instead this now defaults to not showing a menu, withoptions(webr.show_menu = TRUE)
enabling the menu feature globally. -
The
RObject.toObject()
methods have been refined for R lists anddata.frame
objects. The.toObject()
method no longer uses recursion by default when converting R lists and environments, due to the possibility of unconvertible nested R objects. However, for symbols, atomic vectors, and Rdata.frame
objects.toObject()
will convert the object to JavaScript in entirety. For a type-stable conversion, serialise the object with the.toJs()
method instead.
Bug Fixes
-
Fix showing content of lazy loaded files in webR demo app editor component (#320).
-
Contents of the code editor in the webR REPL application is now sourced as a temporary file, allowing for input longer than the default R console input buffer length (#326).
-
R error conditions raised during evaluation of an
RCall
orRFunction
object are now re-thrown as JavaScript exceptions. -
Fixed spelling errors in some JavaScript errors thrown by webR.
-
Useful POSIX scripts from libraries compiled for Wasm are now copied to
$(HOST)/bin
so that$(WASM)/bin
does not need to be put on the path when building Wasm R packages (#327). -
The
symbols.rds
make target should now work when building R packages usingrwasm
(r-wasm/rwasm#13). -
Rasters with negative width or height are now drawn mirrored or flipped when using the canvas graphics device (#350).
-
Include
cex
parameters when calculating font size in canvas graphics device (#348).