V8 version 0.4 has appeared on CRAN. This version introduces several new console functions (
console.error) and two vignettes:
I will talk more about using NPM in another blog post this week.
Starting V8 version 0.4 each context has a
console object in the global namespace:
library(V8) ct <- new_context() ct$eval('console.log("Bla bla")') # Bla bla ct$eval('console.warn("Heads up!")') # Warning: Heads up! ct$eval('console.error("Oh noes!")') # Error: Oh noes!
For example you can use this to verify that external resources were loaded:
ct$source("https://cdnjs.cloudflare.com/ajax/libs/crossfilter/1.3.11/crossfilter.min.js") ct$eval('var cf = crossfilter || console.error("failed to load crossfilter!")')
Of course, in R you could use
The interactive console has been enhanced a bit as well. It no longer prints redundant “undefined” returns:
library(V8) ct <- new_context() ct$console() # This is V8 version 18.104.22.168. Press ESC or CTRL+C to exit.
From here we can try our new functions:
console.log("Bla bla") console.warn("Heads up!") console.error("Oh noes!")
Some silly example illustrating jshint:
library(js) code = "var foo = 123nvar bar = 456nfoo + bar" cat(code) # var foo = 123 # var bar = 456 # foo + bar jshint(code)[c("line", "reason")] # line reason # 1 Missing semicolon. # 2 Missing semicolon. # 3 Expected an assignment or function call and instead saw an expression. # 3 Missing semicolon.
Or the brilliant uglify-js:
uglify_reformat(code) #  "var foo=123;var bar=456;foo+bar;" uglify_optimize(code) # Warning: Dropping side-effect-free statement [null:3,0] #  "var foo=123,bar=456;"