Bridging module: JavaScript < - > R
- 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.
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.
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"));
Please see doc directory.
- node-ffi: Node.js Foreign Function Interface
- ref * Turn Buffer instances into "pointers"
- arian/Complex: Calculations with Complex Numbers in JavaScript
- Factor
- Dataframe
- Console handling
- S3 class
- S4 class
- Graphic handling
Programmed by kcrt (TAKAHASHI, Kyohei) http://profile.kcrt.net/
Copyright © 2017 kcrt (TAKAHASHI, Kyohei)
Released under the MIT license
http://opensource.org/licenses/mit-license.php
- R Internals
- R internals (by Hadley)
- Advanced R by Hadley Wickham
- You can buy Physical copy of this material. Especially recommended!
- Rccp: Seamless R anc C++ Integration
- Rcpp documentation
- Rcpp for everyone (Masaki E. Tsuda)