npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rio

v2.4.1

Published

Integration with Rserve, a TCP/IP server for R framework

Downloads

124

Readme

RIO

Build Status NPM version NGN Dependencies

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, integer, integer array, string, string array, boolean, boolean array objects and raw vector (images or files).

It supports also the plain text and crypted 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 or jsonlite package, deserializing the JSON object, calling a method, serializing the response and returning to Node.js.

Examples

var rio = require("rio");

rio.e({command: "pi / 2 * 2"});
rio.e({command: "c(1, 2)"});
rio.e({command: "as.character('Hello World')"});
rio.e({command: "c('a', 'b')"});
rio.e({command: "Sys.sleep(5); 11"})

rio.$e({
    command: "pi / 2 * 2"
}).then(function (res) {
    console.log(res);
});

rio.e({
    command: "2 + 2"
}).e({
    command: "3 + 3"
});

See examples directory.

  • ex1: Getting started with evaluate api.
  • ex2: How to evaluate a filename and entrypoint.
  • ex3: How to evaluate a filename and host.
  • ex4: An example with utf-8 chars.
  • ex5: How to retrieve a plot.
  • ex6: How to call functions already loaded in R session.
  • ex7: An example with large data packet.
  • ex8: An example with evaluateDefer api.
  • ex9: An example chaining evaluate api.
  • ex10: How to evaluate a matrix, using JSON serialization.

Installation

NPM NPM

To install with npm:

npm install rio

Tested with Node.js 5.x and Rserve 1.7.3, on Windows 10 64 with R 3.2.2 and on Debian Jessie (USB armory) with R 3.1.1.

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)

Methods

evaluate(config) - e(config)

Evaluate a command, connecting to Rserve, executing the command and then disconnecting. The result is passed to the callback.

The defaults for the options parameter:

config = {
    command: "",
    filename: "",

    entrypoint: "",
    data: {},

    callback: function (err, res) {
        if (!err) {
            console.log(res);
        } else {
            console.log("Rserve call failed. " + err);
        }
    },

    host = "127.0.0.1",
    port = "6311",
    path = undefined,

    user = "anon",
    password = "anon"
}
  • command OR filename OR entrypoint need to be filled. Otherwise it is missing the evaluation object.

  • if command AND filename AND entrypoint are empty then error. As above, said in different way.

  • command AND filename are exclusive: if both are not empty then error. Otherwise what does rio evaluate, command or filename?

  • if command AND filename are empty then entrypoint is mandatory. This is the case when rio evaluates a function defined on R side.

  • host AND path are exclusive. rio needs to choose beetween net socket or unix socket transport.

When filename is filled, rio loads the content of a R file, calling finally an entrypoint, passing data.

config = {
    filename: "foo.R",
    entrypoint: "main", // entrypoint is called
    data: { foo: "bar" } // data is stringified and passed to entrypoint
}

When entrypoint is filled, finally passing data, it is used when we need to call a function defined in Rserve instance.

config = {
    entrypoint: "echo",
    data: ["test", "data"],
    callback: printEcho
}

evaluateDefer(config) - $e(config)

Evaluate a command, returning a promise: config options is the same as evaluate.

shutdown(options)

Sends the CMD_shutdown command to the Rserve server. Options are the same as for evaluate.

enableDebug(isDebug)

It enables debugging mode, printing the packet and logging messages on client side.

You may start also a Rserve instance in debugging mode with following commands (on Windows box with Git Bash Shell):

export R_PATH=/c/My/Programs/R
export PATH=$PATH:$R_PATH/bin/x64

$R_PATH/library/Rserve/libs/x64/Rserve_d.exe --

Set your paths accordingly.

enableRecordMode(isRecordMode, options)

It enables record mode, dumping the incoming data to a file specified in the options.

options = {
    fileName: "node-rio-dump.bin"
}

It is useful to record a Rserve session to replay it in an environment without Rserve (for example Travis CI). For instance,

> var rio=require("./index.js")
undefined
> rio.enableRecordMode(true, {fileName: "test/dump/integer-test.bin"});
undefined
> rio.evaluate({command: "as.integer(3)"})
undefined
> 3
(^C again to quit)

Then, you need to export the variable CI to emulate CI environment: export CI=true

Eventually npm test.

enablePlaybackMode(isPlaybackMode, options)

It enables playback mode, reading a dump file instead connecting to the server.

options = {
    fileName: "node-rio-dump.bin"
}

Contributors

project  : node-rio
repo age : 4 years, 5 months
active   : 111 days
commits  : 256
files    : 59
authors  :
  227  icebox                  88.7%
    8  Alberto Santini         3.1%
    7  Manuel Santillan        2.7%
    6  albertosantini          2.3%
    3  Karthik Madathil        1.2%
    2  Anand Patil             0.8%
    1  Alex Proca              0.4%
    1  Farrin Reid             0.4%
    1  Koichiro Sobue          0.4%