mongo.bson.buffer.append.complex(buf, name, value)
If value has a dims
attribute of length > 1, any names
or
dimnames
attribute is ignored and a nested array is appended. (Use
mongo.bson.buffer.append.object()
if you want to preserve
dimnames
).
If value has a names attribute, a subobject is appended and the subfields are given the indicated names.
Otherwise, if more than one element is present in value, the values are appended as a subarray.
In the last case, a single complex is appended as the value of the field.
mongo.bson.buffer.append
.
buf <- mongo.bson.buffer.create()
mongo.bson.buffer.append.complex(buf, "Alpha", 3.14159 + 2i)
b <- mongo.bson.from.buffer(buf)
# The above produces a BSON object of the form:
# { "Alpha" : { "r" : 3.14159, "i" : 2 } }
buf <- mongo.bson.buffer.create()
mongo.bson.buffer.append.complex(buf, "complexi", c(1.7 + 2.1i, 97.2))
b <- mongo.bson.from.buffer(buf)
# The above produces a BSON object of the form:
# { "complexi" : [ { "r": 1.7, i : 2.1}, { "r": 97.2, "i" : 0} ] }
buf <- mongo.bson.buffer.create()
values <- c(0.5 + 0.1i, 0.25)
names(values) <- c("Theta", "Epsilon")
mongo.bson.buffer.append.complex(buf, "Values", values)
b <- mongo.bson.from.buffer(buf)
# The above produces a BSON object of the form:
# { "Values" : { "Theta" : { "r" : 0.5, "i" : 0.1 },
# "Epsilon" : { " r" : 0.25, "i" : 0 } } }
Run the code above in your browser using DataLab