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