libr-bridge/develop.mjs
"use strict";
import R from "./R";
import { RFactor, RDataFrame } from "./RObject";
/* Execute this script with:
* node -r @std/esm example.mjs
* or
* node --experimental-modules example.mjs
* If something is wrong, try with:
* DEBUG=libr-bridge:* node -r @std/esm example.mjs
*/
const r = new R();
const data = {
"id": [ 12345, 23456, 34567 ],
"Name": ["apple", "banana", "orange"],
"Color": new RFactor(["red", "yellow", "orange"])
};
const data2 = new Map([
["id", [ 12345, 23456, 34567 ]],
["Name", ["apple", "banana", "orange"]],
["Color", new RFactor(["red", "yellow", "orange"])]
]);
/*
const df = new RDataFrame(data);
r.setVar("mydataframe", df);
r.eval("print(mydataframe)");
console.log(r.eval("typeof(mydataframe$Name)"));
console.log(r.eval("mydataframe$Name"));
console.log(r.eval("mydataframe$Color")); */
r.setVar("mydataframe2", new RDataFrame(data2));
console.log(r.eval("iris"));
/*
* vim: filetype=javascript
*/