Learn R Programming

cdb (version 0.0.1)

write.cdb: Writes a data frame to a text file

Description

This function writes a two column data frame to a text file using the cdb record format.

Usage

write.cdb(x, file, type=c("cdb","txt"))

Arguments

x
An object that can be coerced as a data frame with two columns.
file
The name of the cdb file to write.
type
A character string describing the type of file. Value cdb does nothing; txt writes a text file using the cdb record format. See the Details section.

Value

A text file with all the keys and values.

Details

This function writes a data frame to a file using the text version of the cdb format. The data frame (or the object) must have only two columns: The first one contains the keys and the second column are the values.

The text version of the constant databse is a file with several lines with the form of +klen,vlen:key->value followed by a newline. klen and vlen are the number of bytes in key and in value, respectively. The end of data is indicated by an extra newline.

References

D. J. Bernstein The cdbmake and cdbdump programs http://cr.yp.to/cdb/cdbmake.html Michael Tokarev (2012) TinyCDB - a Constant DataBase http://www.corpit.ru/mjt/tinycdb.html

See Also

read.cdb

Examples

Run this code
set.seed(123)
a <- data.frame(key=rnorm(10),value=rnorm(10))
write.cdb(a, "Base.txt", type="txt")

# Create a cdb base using an external program.
# For instance, using the TinyCDB program:
## Not run: system("cdb -c Base.cdb Base.txt")

Run the code above in your browser using DataLab