Skip to content

Instantly share code, notes, and snippets.

@jeroen
Last active August 29, 2015 14:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeroen/9e4dc12a70b7e880fbed to your computer and use it in GitHub Desktop.
Save jeroen/9e4dc12a70b7e880fbed to your computer and use it in GitHub Desktop.
Fun with V8 console
# Execute this script line by line in your favorite IDE
# It does not work via source()
library(V8)
data(diamonds, package="ggplot2")
# Create session
ct <- new_context()
ct$source("http://cdnjs.cloudflare.com/ajax/libs/crossfilter/1.3.11/crossfilter.min.js")
ct$assign("diamonds", diamonds)
# Enter the JavaScript console
ct$console()
//now we are in javasript :)
var cf = crossfilter(diamonds)
var price = cf.dimension(function(x){return x.price})
var depth = cf.dimension(function(x){return x.depth})
price.filter([2000, 3000])
JSON.stringify(depth.top(10))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment