V8 version 0.4: console.log and exception handling
January 13, 2015
V8 version 0.4 has appeared on CRAN. This version introduces several new console functions (console.log
, console.warn
, console.error
) and two vignettes:
I will talk more about using NPM in another blog post this week.
JavaScript Exceptions
Starting V8 version 0.4 each context has a console
object in the global namespace:
The console.log
, console.warn
and console.error
functions can be used to generate stdout, warnings or errors in R from JavaScript. This allows for writing embedded JavaScript functions that propagate exceptions back to R, similar as we would do for other foreign language interfaces such as C or C++:
For example you can use this to verify that external resources were loaded:
Of course, in R you could use tryCatch
or whatever you like to catch exceptions that were raised this way in your JavaScript code.
Interactive Console
The interactive console has been enhanced a bit as well. It no longer prints redundant “undefined” returns:
From here we can try our new functions:
Bindings to JavaScript Libraries
V8 provides a JavaScript call interface, data interchange, exception handling and interactive debugging console. This is everything we need to embed JavaScript code and libraries in R.
If you are curious how this would work, I have started working on a new R package implementing bindings to some of the very best libraries available for working with JavaScript and HTML. I hope this package will make it’s way to CRAN soon, but until then it is available from github
Some silly example illustrating jshint:
Or the brilliant uglify-js: