|
| 1 | +# Processing.R Design and Architecture |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +Processing.R is an R language mode for Processing and the Processing Development Environment (PDE). With Processing.R users can write Processing sketches in the PDE using the R language. |
| 6 | + |
| 7 | +[Processing](http://processing.org/) is a flexible software sketchbook and a language for learning how to code within the context of the visual arts. Since 2001, Processing has promoted software literacy within the visual arts and visual literacy within technology. There are tens of thousands of students, artists, designers, researchers, and hobbyists who use Processing for learning and prototyping. |
| 8 | + |
| 9 | +[The Processing Development Environment (PDE)](https://processing.org/reference/environment/) makes it easy to write Processing programs. Programs are written in the Text Editor and started by pressing the Run button. In Processing, a computer program is called a sketch. Sketches are stored in the Sketchbook, which is a folder on your computer. |
| 10 | + |
| 11 | +[Programming modes](https://processing.org/reference/environment/#Programming_modes) in Processing make it possible to deploy sketches on different platforms and program in different ways. The default is Java mode. Other programming modes include [python mode](http://py.processing.org/), [native javascript mode](https://p5js.org/) and [android mode](http://android.processing.org/). These modes allow users of a specific language to get started with Processing easily. |
| 12 | + |
| 13 | +[R](https://www.r-project.org/) is a language and free software environment for statistical computing and graphics. It compiles and runs on a wide variety of UNIX platforms, Windows and MacOS. |
| 14 | + |
| 15 | +[renjin](http://www.renjin.org/) is a JVM-based interpreter for the R language for statistical computing. Processing.R uses renjin to run R language sketches in JVM using Processing's default Java API. The Processing.R mode has a similiar architecture to [python mode](http://py.processing.org/), which uses Jython. |
| 16 | + |
| 17 | +## Architecture |
| 18 | + |
| 19 | +Processing.R is available in two forms: |
| 20 | + |
| 21 | +* The Processing.R JAR wrapper, `runner.jar`. |
| 22 | +* The Processing.R PDE language mode, `RLangMode`. |
| 23 | + |
| 24 | +These two forms share the same architecture. |
| 25 | + |
| 26 | +### COMMON |
| 27 | + |
| 28 | +#### `RLangPApplet` |
| 29 | + |
| 30 | +`RLangPApplet` is a class that extends `BuiltinApplet`. `RLangPApplet` overrides built-in functions such as `draw`, `settings` and `setup`. `RLangPApplet` calls renjin, which is the JVM interpreter for R, to evaluate the R code. |
| 31 | + |
| 32 | +#### `BuiltinApplet` |
| 33 | + |
| 34 | +`BuiltinApplet` is the layer that maps between the Processing Java API and the R language as implemented in renjin. For example, it defines a function to cast parameters from integer to double in order to fit the Processing API. |
| 35 | + |
| 36 | +### JAR |
| 37 | + |
| 38 | +Want to understand `runner.jar`? Start with `Runner`. |
| 39 | + |
| 40 | +#### `Runner` |
| 41 | + |
| 42 | +`Runner` is the class to run Processing.R sketches. It initializes an `RLangPApplet` instance and calls `runSketchBlocking` to run a Processing.R sketch. The entry of `runner.jar` is the `main` function in `Runner`. |
| 43 | + |
| 44 | +#### `SketchRunner` |
| 45 | + |
| 46 | +`SketchRunner` interacts with `Runner` to run the Processing.R sketches. It is the middle layer between `Runner` and `SketchServiceRunner`. |
| 47 | + |
| 48 | +#### `SketchServiceRunner` |
| 49 | + |
| 50 | +`SketchServiceRunner` is a standalone process out of the mode. It calls the `main` function in `SketchRunner`. |
| 51 | + |
| 52 | +### PDE MODE |
| 53 | + |
| 54 | +Want to understand the Processing Development Environment(PDE) mode? Start with `RLangMode`. |
| 55 | + |
| 56 | +#### `RLangMode` |
| 57 | + |
| 58 | +`RLangMode` is the main class for the Processing.R PDE mode. It is accessed through reflection. Processing.R uses Java Remote Method Invocation(RMI), to solve the performance problem. Processing.R mode creates some long-running processes(`SketchServiceRunner`) to handle the requests from Processing Development Environment(PDE). |
| 59 | + |
| 60 | +#### `RLangEditor` |
| 61 | + |
| 62 | +`RLangEditor` is the class that represents the built-in text editor for R mode in the Processing Development Environment(PDE). It extends PDE's `Editor`, builds the mode editor, and initializes all related components, such as a formatter toolbar. |
| 63 | + |
| 64 | +#### `ModeService` and `SketchServiceManager` |
| 65 | + |
| 66 | +`ModeService` is a Remote Method Invocation(RMI) interface, which extends `java.rmi.Remote`. `SketchServiceManager` is the class which implements `ModeService`. `RLangMode` creates a `SketchServiceManager` instance when started. `SketchServiceManager` manages all `SketchServiceRunner`s, and `SketchServiceRunner` runs the real logic of Processing.R sketches. |
| 67 | + |
| 68 | +## Reference |
| 69 | + |
| 70 | +* "Processing.org". Processing.org. N.p., 2017. Web. 17 June 2017. |
0 commit comments