Skip to content

Commit

Permalink
Find names in attributes
Browse files Browse the repository at this point in the history
Rather than assuming its the first element
  • Loading branch information
tmelliott committed Jul 17, 2024
1 parent b71d969 commit 9c921cb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/mighty-vans-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"rserve-ts": patch
---

Fix vector bug where names ignored if not first attribute
23 changes: 11 additions & 12 deletions src/Rserve.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,19 @@ var Rserve = (function () {
if (_.isUndefined(this.attributes)) {
return values;
} else {
// FIXME: there is no reason why names should be the first or only
// attribute, so the code should really look
// for "names" and not cry if it doesn't exist
if (this.attributes.value[0].name == "names") {
var keys = this.attributes.value[0].value.value;
var result = {};
_.each(keys, function (key, i) {
result[key] = values[i];
});
return result;
}
const namesIndex = this.attributes.value.findIndex(
(v) => v.name === "names"
);
if (namesIndex === -1) return values;
var keys = this.attributes.value[namesIndex].value.value;
var result = {};
_.each(keys, function (key, i) {
result[key] = values[i];
});
return result;

// FIXME: how can we pass other important attributes
// like "class" ?
return values;
}
},
}),
Expand Down
9 changes: 9 additions & 0 deletions src/playground.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import RserveClient from "./index";
import { ocapFuns } from "../tests/r_files/oc";
import * as RT from "./types";
import { z } from "zod";

// set global WebSocket
global.WebSocket = require("ws");
Expand Down Expand Up @@ -68,6 +69,14 @@ const noOcap = async () => {
console.log(tbl2.r_attributes.dimnames);
}

const iris = await R.eval(
"head(iris)",
z.object({
data: z.any(),
})
);
console.log("Iris ...", iris);

// R.integer(3, {
// dimnames: z.object({
// "": R.character(),
Expand Down

0 comments on commit 9c921cb

Please sign in to comment.