Skip to content

webR 0.3.0

Compare
Choose a tag to compare
@georgestagg georgestagg released this 22 Mar 13:23
· 25 commits to main since this release
9e02552

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 a EMFC environment variable in the user's environment. If this variable points to an existing flang-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 argument capture, defaulting to FALSE. When TRUE, plots are captured into a canvas cache on the webR worker thread. The cache may be accessed from JavaScript through Module.webr.canvas. Entries in the canvas cache are destroyed using webr::canvas_purge() or webr::canvas_destroy(id). In this way, the captureR() method now captures plots by default (see below).

  • The RCall and RFunction classes now have a capture(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, and ArrayBufferView (e.g. Uint8Array) may now be used with the RRaw R object constructor. The generic RObject 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 class data.frame. Direct construction with RList() does not create a data.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 of ImageBitmap objects in the property images. The previous behaviour may be restored either by manually starting a non-capturing webr::canvas() device during execution, or by including captureGraphics: false as part of the options argument. The default options for evalR() 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. The emfc wrapper script is no longer required, but for the moment the Make variable pointing to the flang-new compiler is still named EMFC 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 R library() and require() 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 using evalR() (#324). The new shims also ensure that library() and require() 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, with options(webr.show_menu = TRUE) enabling the menu feature globally.

  • The RObject.toObject() methods have been refined for R lists and data.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 R data.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 or RFunction 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 using rwasm (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).