RIO, R Input Output, connects an app to Rserve, a TCP/IP server which allows other programs to use facilities of R.
It supports double, double array, string, string array boolean, boolean array objects and raw vector (images or files).
It supports also the plain text authentication, if Rserve is configured for that capability.
The main goal is to pass a string containing a script call using a JSON object as parameter. Then, inside the script, using RJSONIO package, deserializing the JSON object, calling a method, serializing the response and returning to NodeJS.
var rio = require('rio');
rio.evaluate("pi / 2 * 2");
rio.evaluate('c(1, 2)');
rio.evaluate("as.character('Hello World')");
rio.evaluate('c("a", "b")');
rio.evaluate('Sys.sleep(5); 11')
See examples
directory.
ex1
: Getting started withevaluate
api.ex2
: How to evaluate a script, to call a function passing params withsourceAndEval
.ex3
: How to callsourceAndEval
with a config object including connection details.ex4
: An example with utf-8 chars.ex5
: How to retrieve a plot.
To install with npm:
npm install rio
Tested with node 0.10.x and Rserve 1.7.3 (on Windows 7) with R 3.1.0.
Don't forget to start Rserve. For instance, from R console, after installing the package Rserve:
require('Rserve')
Rserve()
To shutdown the server from R console:
require('RSclient')
c <- RSconnect()
RSshutdown(c)
Evaluate a command, connecting to Rserve, executing the command and then disconnecting.
The defaults for the options parameter:
options = {
callback: function (err, res) {
if (err) {
util.puts(res);
} else {
util.puts("Rserve call failed. " + err);
}
},
host = "127.0.0.1",
port = 6311,
path = undefined,
user = "anon",
password = "anon"
}
Either define path
, the path of a Unix socket, or host
/port
.
It loads the content of a R file and calls the evaluate
method, merging,
finally, the options parameter:
options = {
entryPoint: "main", // entryPoint is called
data: { foo: "bar" } // data is stringified and passed to entryPoint
}
It is an helper method to call evaluate
, adding to the buffer string, the call
of the entry point. Options are the same as for evaluate
.
Sends the CMD_shutdown
command to the Rserve server. Options are the same as
for evaluate
.
It enables debugging mode, printing the packet and logging messages.
It enables record mode, dumping the incoming data to a file specified in the options.
options = {
fileName: "node-rio-dump.bin"
}
It enables playback mode, reading a dump file instead connecting to the server.
options = {
fileName: "node-rio-dump.bin"
}
project : node-rio
repo age : 2 years, 9 months
active : 64 days
commits : 148
files : 38
authors :
135 icebox 91.2%
6 albertosantini 4.1%
4 Manuel Santillan 2.7%
2 Anand Patil 1.4%
1 Farrin Reid 0.7%