OpenCPU client
JavaScript
Permalink
Failed to load latest commit information.
examples
lib Change packages calls for session support. Sep 10, 2015
test Refactor tests with tape. Jan 30, 2016
.eslintrc.yml Rename .eslintrc to .eslintrc.yml. Nov 25, 2015
.gitattributes Add the initial implementation of the client. Aug 28, 2013
.gitignore Add the initial implementation of the client. Aug 28, 2013
.npmignore Add the initial implementation of the client. Aug 28, 2013
.travis.yml Update Travis CI to containter-infrastructure. Sep 12, 2015
CHANGELOG.md
LICENSE Add the initial implementation of the client. Aug 28, 2013
README.md
index.js Replace jshint with eslint. Mar 4, 2015
package.json Update request 2.74.0. Jul 23, 2016

README.md

NODE-OPENCPU

Build Status NPM version

node-opencpu is a OpenCPU client.

Example

var opencpu = require("opencpu");

opencpu.rCall("/library/datasets/R/mtcars/json", {}, function (err, data) {
    if (!err) {
        console.log(data[0].mpg + data[1].mpg); // => 42
    } else {
        console.log("opencpu call failed.");
    }
});

opencpu.rCall("/library/stats/R/rnorm/json", {
    n: 42,
    mean: 10,
    sd: 10
}, function (err, data) {
    if (!err) {
        console.log(data.length); // => 42
    } else {
        console.log("opencpu call failed.");
    }
});

Installation

NPM NPM

To install with npm:

npm install opencpu

Tested with Node.js 5.x and OpenCPU 1.5.1 (with R 3.2.3).

Don't forget to start the opencpu server. For instance, from R console, after installing the package opencpu. The OpenCPU server will automatically be started when the opencpu package is attached. By default, the server starts at a random port. The default port used by node-opencpu is 5307.

> library(opencpu)
Initiating OpenCPU server...
Creating new config file: C:\Users\icebox\Documents/.opencpu.conf
OpenCPU started.
[httpuv] http://localhost:5985/ocpu
OpenCPU single-user server ready.
> opencpu$stop()
OpenCPU stopped.
> opencpu$start(5307)
Using config: C:\Users\icebox\Documents/.opencpu.conf
OpenCPU started.
[httpuv] http://localhost:5307/ocpu
Warning message:
closing unused connection 3 (<-icebox-vpcz1:11823)
>