mongo.bson.buffer.append.complex: Append a double field onto a mongo.bson.buffer

Description Usage Arguments Details Value See Also Examples

View source: R/bson.R

Description

Append a double or vector of doubles onto a mongo.bson.buffer.

Usage

1

Arguments

buf

(mongo.bson.buffer) The buffer object to which to append.

name

(string) The name (key) of the field appended to the buffer.

value

(complex vector) The values(s) to append to the buffer.

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.

Details

Note that since BSON has no built-in complex type, R's complex values are appended as subobjects with two fields: "r" : the real part and "i" : the imaginary part.

Value

TRUE if successful; otherwise, FALSE if an error occured appending the data.

See Also

mongo.bson,
mongo.bson.buffer,
mongo.bson.buffer.append.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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 } } }

jonkatz2/rmongodb documentation built on May 19, 2019, 7:30 p.m.