What is V8 (not)

The R package V8 provides a direct interface to Google’s high performance JavaScript engine. The V8 engine is also used in Chrome, NodeJS, MongoDB, and many other software.

However each of these programs actually implements most JavaScript functionality on top of V8. The naked V8 engine only provides pure ECMAscript, which does not include a lot of things that you might be used to. There is no I/O (network/disk) and no DOM (window).

Recent versions of V8 do have an event loop (required for async in ES6) and WASM support.

JS Engine Evented Network Disk DOM WASM
Browser -
Node -
V8 (6+) - - -
Legacy V8 (3.14) - - - - -

As of 2019, we support modern V8 (ES6+) on all important systems. See the installation instructions for more details.

Using JavaScript libraries

You can load JavaScript libraries in V8, but beware that not all packages will work out of the box. Most libraries in npm are primarily written for Node or the browser. Functionality that requires internet connectivity, a browser window, or file access won’t work, but there is a lot of stuff that does work.

ct <- v8()
ct$source(system.file("js/underscore.js", package = "V8"))
ct$call("_.filter", mtcars, JS("function(x){return x.mpg < 15}"))
                     mpg cyl disp  hp drat    wt  qsec vs am gear carb
Duster 360          14.3   8  360 245 3.21 3.570 15.84  0  0    3    4
Cadillac Fleetwood  10.4   8  472 205 2.93 5.250 17.98  0  0    3    4
Lincoln Continental 10.4   8  460 215 3.00 5.424 17.82  0  0    3    4
Chrysler Imperial   14.7   8  440 230 3.23 5.345 17.42  0  0    3    4
Camaro Z28          13.3   8  350 245 3.73 3.840 15.41  0  0    3    4

JS libraries that don’t do anything online or graphical generally work out of the box.