Description Usage Arguments Details Value See Also Examples
Append an R object onto a mongo.bson.buffer.
1 | mongo.bson.buffer.append.object(buf, name, value)
|
buf |
(mongo.bson.buffer) The buffer object to which to append. |
name |
(string) The name (key) of the field appended to the buffer. |
value |
(object) The object to append to the buffer as a subobject. |
This function allows you to store higher level R objects in the database without losing their attribute information. It will correctly handle data frames, matrices and arrays for instance; although, empty objects, such as a data frame with no rows, are not permitted.
Note that the names attribute will not be preserved if the object is multidimensional (although dimnames will be).
The object's value will look like this in the buffer:
1 2 3 |
name
will be substituted with the value of the name
parameter.
xxx
will be substituted with the low level value of the
object (as would be appended by
mongo.bson.buffer.append()
).
attr1
and attr2
will be substituted with the names of attributes.
yyy
and
zzz
will be substituted with the values of those attributes.
Note that it is inadvised to construct this wrapper manually as
mongo.bson.value()
and
mongo.bson.iterator.value()
bypass the special checking and
handling that is done by R code that set attributes.
TRUE if successful; otherwise, FALSE if an error occured appending the data.
mongo.bson,
mongo.bson.buffer,
mongo.bson.buffer.append
,
mongo.bson.value
,
mongo.bson.iterator.value
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | age <- c(5, 8)
height <- c(35, 47)
d <- data.frame(age=age, height=height)
buf <- mongo.bson.buffer.create()
mongo.bson.buffer.append.object(buf, "table", d)
b <- mongo.bson.from.buffer(buf)
# this produces a BSON object of the form:
# { "table" : { "R_OBJ" : true,
# "value" : {
# "age" : [ 5, 8 ],
# "height" : [35, 47 ]
# },
# "attr" : {
# "row.names" : [ -2147483648, -2 ],
# "class" : "data.frame"
# }
# }
# }
# row.names is stored in the compact form used for integer row names.
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.