Use R from JavaScript(Node)
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
doc
images
test
.esdoc.json
.eslintignore
.eslintrc.json
.gitignore
.tern-project
.travis.yml
R.mjs
README.md
RObject.mjs
SEXPWrap.mjs
example.mjs
index.js
index.mjs
libR.mjs
license.js
logo.png
package.json
safe-windows-registry.js
yarn.lock

README.md

libr-bridge

Travis CI

Bridging module: JavaScript < - > R

🄬🌉⬢

Sorry! It's under development.

  • Some important features including S3/S4 object handling and expression are not supported yet!
  • Incompatible API changes may be held.
  • Please do not use in the production environment until specifications are fixed.
  • Pull requests are always welcome.

What is libr-bridge?

libr-bridge is a very powerful npm package which enables you to use R function/statistical method in Node.js environment.

R (The R Foundation, Vienna, Austria) is a free software environment for statistical computing. With libr-bridge, you can use function in R as if they were JavaScript native function.

How to Use

Following samples and libr-bridge are written with ECMAScript 6 modules syntex (import/export). Please use esm or --experimental-modules.

let r = new R();

const arrA = [1.00, 3.36, 8.01, 1.22, 3.74, 2.43, 7.95, 8.32, 7.45, 4.36];
const arrB = [1.04, 3.65, 6.82, 1.46, 2.70, 2.49, 7.48, 8.28, 8.93, 5.63];

/* Some functions are already loaded to libr-bridge */
console.log("Mean of arrA: " + r.mean(arrA));
console.log("Mean of arrB: " + r.mean(arrB));
console.log("Peason's correlation coefficient: " + r.cor(arrA, arrB));

/* You can pass data to R */
r.setVar("a", arrA);

/* And data can be used in R */
console.log(r.eval('sum(a)'));
r.eval('b <- a / 2');
console.log(r.eval('b'));

/* You can receive data from R */
let b = r.getVar("b");

/* Execute complex command with eval. */
r.eval(`
	myfactorial <- function(x) {
		if (x == 0) {
			return(1)
		} else {
			return(x * myfactorial(x - 1))
		}
	}
`);
let factorial_50 = r.func("myfactorial")(50);
console.log(factorial_50);

console.log(r.eval("iris"));

API

Document

Please see doc directory.

Depending package

npm

  1. node-ffi: Node.js Foreign Function Interface
  2. ref * Turn Buffer instances into "pointers"
  3. arian/Complex: Calculations with Complex Numbers in JavaScript

My TODO list

  • Factor
  • Dataframe
  • Console handling
  • S3 class
  • S4 class
  • Graphic handling

Author information

Programmed by kcrt (TAKAHASHI, Kyohei) http://profile.kcrt.net/

License

Copyright © 2017 kcrt (TAKAHASHI, Kyohei)
Released under the MIT license
http://opensource.org/licenses/mit-license.php

Reference

English

  1. R Internals
  2. R internals (by Hadley)
  3. Advanced R by Hadley Wickham
    • You can buy Physical copy of this material. Especially recommended!
  4. Rccp: Seamless R anc C++ Integration
  5. Rcpp documentation
  6. Rcpp for everyone (Masaki E. Tsuda)

Japanese

  1. R入門 Ver.1.7.0
  2. R言語定義 Ver.1.1.0 DRAFT
  3. Rの拡張を書く Ver2.1.0
  4. R言語徹底解説 Hadley Wickham (著), 石田 基広ら (翻訳) 特におすすめです。
  5. みんなのRcpp (Masaki E. Tsuda)