The SpiderMoneky package

Last Release: 0.2-0 (18 Jul 2013)

This package provides a means of evaluating JavaScript code, creating JavaScript objects and calling JavaScript functions and methods from within R. This can work by embedding the JavaScript engine within an R session or by embedding R in an browser such as Firefox and being able to call R from JavaScript and call back to JavaScript from R.

The package is a thin R layer on top of the JavaScript API provided by the Mozilla implementation of JavaScript - SpiderMonkey.

The code is programmatically generated using the RGCCTranslationUnit and RGCCTUFFI packages and uses the Rffi package to implement the invocation of the C routines (rather than .C() and .Call()).

Why is this useful?

The primary motivation is to allow R programmers manipulate JavaScript objects such as the DOM and all of its properties and methods without having to write JavaScript code. This is useful when we embed R inside a Web browser such as Firefox as an extension. JavaScript code can call R and then that R code can These R functions can work with data in R and in JavaScript and can produce statistical content that is dynamically displayed within the browser. The same can be done by writing JavaScript code that calls R functions, but this

A second use of this package is to allow R programmers to utilize code written in JavaScript. Most JavaScript code is designed for Web pages and needs the DOM object to be of use. However, JavaScript is seeing increased use and people are writing libraries in JavaScript to do different things outside of the DOM.

At the very least, we can use this to emulate a Web browser and how it handles Web pages. We can download the HTML for a page and evaluate the JavaScript content to mimic how, for example, forms are processed by dynamic JavaScript code.


There are help pages for all of the functions and several non-trivial examples including a description of the implementation of the GeoIP package in that package.

  • Duncan Temple Lang <>
    Last modified: Wed Jan 26 16:15:31 PST 2011