Cloud2016 放假尝试了下 graalvm,在 nodejs 中调用 R,实现一个脚本非常简单。
比如:
/Library/Java/JavaVirtualMachines/graalvm/Contents/Home/bin/node --polyglot --jvm tmp.js
var JavaPI = Java.type('java.lang.Math').PI;
console.log(JavaPI);
// Load the R module
console.log("Preparing weather model");
// fs = require('fs');
//var weatherModelScript = fs.readFileSync("weatherModel.r", "utf8");
var rand_num = Polyglot.eval("R", "runif(100)");
console.log(rand_num);
输出
3.141592653589793
Preparing weather model
[Array: null prototype] [
0.547540019499138,
0.12333883391693234,
0.6018097621854395,
0.5529381702654064,
0.6666839295066893,