- Notifications
You must be signed in to change notification settings - Fork29
Embedded JavaScript Engine for R
License
jeroen/V8
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Embedded JavaScript and WebAssembly Engine for R
An R interface to V8: Google's open source JavaScript and WebAssemblyengine. This package can be compiled either with V8 version 6 and up or NodeJSwhen built as a shared library.
About the R package:
- Vignette:Introduction to V8 for R
- Vignette:Using NPM packages in V8 with browserify
To see some quick examples in R run:
library(V8)example(v8)
Binary packages forOS-X orWindows can be installed directly from CRAN:
install.packages("V8")
On Linux you need a suitable libv8 installation, see below.
On amd64/arm64 Linux/MacOS platforms it is possible (and recommended) to automatically download a suitable static build of libv8 during package installation. This is enabled by default on Ubuntu, RHEL, and MacOS. For other systems you can opt-in by setting an environment variableDOWNLOAD_STATIC_LIBV8
during installation, for example:
Sys.setenv(DOWNLOAD_STATIC_LIBV8=1)install.packages("V8")
This way, you can install the R package on any x64 Linux system, without external system requirements. Alternatively, it is also still possible to install libv8 from your distribution as described below. This may be needed for servers running other architectures, or when building the R package without internet access.
Installation from source on Linux requireslibv8
. On Ubuntu / Debian you need to install eitherlibv8-dev, orlibnode-dev. On the latest systems,libv8-dev
is actually an alias forlibnode-dev
so they are the same:
# Debian and Ubuntusudo apt-get install -y libv8-dev
OnFedora we need v8-devel (which Fedora provides as part ofnodejs):
sudo yum install v8-devel
OnCentOS 7 / RHEL 7 we install first need to enable EPEL:
sudo yum install epel-releasesudo yum install v8-devel
OnRockyLinux 8 / RHEL 8,v8-devel
can be installed from thenodejs:16-epel
module repository:
yum --refresh --enablerepo=epel-testing-modular install @nodejs:16-epel/minimal v8-devel
Arch users are advised to install thev8-r
package, which has been configured to work well with R. Installation can done through your preferred AUR helper such as yay, Trizen, etc. However, since V8 contains a large codebase and (re-)compilation takes a while, users may prefer to build and update it manually. For example,
## Archcd /tmpyay -G v8-rcd v8-rmakepkg -si
OnOS-X usev8 from Homebrew:
brew install v8
But it is much easier to setDOWNLOAD_STATIC_LIBV8
instead.
# Create a new contextlibrary(V8)ctx<- v8()# Evaluate some codectx$eval("var foo = 123")ctx$eval("var bar = 456")ctx$eval("foo+bar")# Assign / get objectsctx$assign("foo", JS("function(x){return x*x}"))ctx$assign("bar", JS("foo(9)"))ctx$get("bar")
Call functions from JavaScript libraries
ctx<-V8::v8()ctx$source("https://cdnjs.cloudflare.com/ajax/libs/coffee-script/1.4.0/coffee-script.min.js")jscode<-ctx$call("CoffeeScript.compile","square = (x) -> x * x",list(bare=TRUE))ctx$eval(jscode)ctx$call("square",9)
About
Embedded JavaScript Engine for R
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors10
Uh oh!
There was an error while loading.Please reload this page.