Learn R Programming

DDIwR (version 0.19)

exportCodebook: Export a DDI Codebook to an XML file.

Description

Create a DDI Codebook version 2.6, XML file structure.

Usage

exportCodebook(codeBook, to = "", OS = "", indent = 2, ...)

Value

An XML file containing a DDI version 2.6 metadata.

Arguments

codeBook

A standard element of class "DDI".

to

either a character string naming a file or a connection open for writing ("" indicates output to the console)

OS

The target operating system, for the eol - end of line character(s)

indent

Indent width, in number of spaces

...

Other arguments, mainly for internal use

Author

Adrian Dusa

Details

#' The information object is a codeBook DDI element having at least two main children:

  • fileDscr, with the data provided as a sub-component named datafile

  • dataDscr, having as many components as the number of variables in the (meta)data.

For the moment, only DDI codebook version 2.6 is exported, and DDI Lifecycle is planned for future releases.

A small number of required DDI specific elements and attributes have generic default values, if not otherwise specified in the codeBook list object. For the current version, these are: monolang, xmlang, IDNo, titl, agency, URI (for the holdings element), distrbtr, abstract and level (for the otherMat element).

The codeBook object is exported as provided, and it is the user's responsibility to test its validity against the XML schema. Most of these arguments help create the mandatory element stdyDscr, which cannot be harvested from the dataset. If this element is not already present, providing any of these arguments via the three dots ... gate, signal an automatic creation and inclusion with the values provided.

Argument xmlang expects a two letter ISO country coding, for instance "en" to indicate English, or "ro" to indicate Romanian etc. The original DDI Codebook attribute is called xml:lang, which for obvious reasons had to be renamed into this R function.

A logical argument monolang signal if the document is monolingual, in which case the attribute xmlang is placed a single time for the entire document in the codeBook element. For multilingual documents, xmlang should be placed in the attributes of various other (child) elements, for instance abstract, or the study title, name of the distributing institution, variable labels etc.

The argument OS can be either:
"windows" (default), or "Windows", "Win", "win",
"MacOS", "Darwin", "Apple", "Mac", "mac",
"Linux", "linux".

The end of line separator changes only when the target OS is different from the running OS.

The argument indent controls how many spaces will be used in the XML file, to indent the different sub-elements.

See Also

Examples

Run this code
if (FALSE) {
exportCodebook(codeBook, to = "codebook.xml")

# using a namespace
exportCodebook(codeBook, to = "codebook.xml", xmlns = "ddi")
}

Run the code above in your browser using DataLab