Skip to content

Commit bdd7448

Browse files
author
Carlos Scheidegger
committed
Merge pull request cscheid#18 from s-u/patch-1
don't break on vectors with other attributes like 'class'
2 parents 2a5e0b5 + 5f506d9 commit bdd7448

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/robj.js

+19-8
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,20 @@ Rserve.Robj = {
5555
if (_.isUndefined(this.attributes)) {
5656
return values;
5757
} else {
58-
if(this.attributes.value[0].name!="names")
59-
throw "expected names here";
60-
var keys = this.attributes.value[0].value.value;
61-
var result = {};
62-
_.each(keys, function(key, i) {
63-
result[key] = values[i];
64-
});
65-
return result;
58+
// FIXME: there is no reason why names should be the first or only
59+
// attribute, so the code should really look
60+
// for "names" and not cry if it doesn't exist
61+
if (this.attributes.value[0].name == "names") {
62+
var keys = this.attributes.value[0].value.value;
63+
var result = {};
64+
_.each(keys, function(key, i) {
65+
result[key] = values[i];
66+
});
67+
return result;
68+
}
69+
// FIXME: how can we pass other important attributes
70+
// like "class" ?
71+
return values;
6672
}
6773
}
6874
}),
@@ -78,6 +84,11 @@ Rserve.Robj = {
7884
if (_.isUndefined(this.attributes)) {
7985
return values;
8086
} else {
87+
// FIXME: lang doens't have "names" attribute since
88+
// names are sent as tags (langs are pairlists)
89+
// so this seems superfluous (it is dangerous
90+
// if lang ever had attributes since there is
91+
// no reason to fail in that case)
8192
if(this.attributes.value[0].name!="names")
8293
throw "expected names here";
8394
var keys = this.attributes.value[0].value.value;

0 commit comments

Comments
 (0)