Create a DDI Codebook version 2.6, XML file structure.
exportCodebook(
codeBook,
to = "",
OS = "",
indent = 2,
...,
session = NULL,
revision = NULL
)An XML file containing a DDI version 2.6 metadata.
A standard element of class "DDI".
either a character string naming a file or a connection open for
writing ("" indicates output to the console)
Home-directory paths beginning with ~ are expanded before writing.
The target operating system, for the eol - end of line character(s)
Indent width, in number of spaces
Other arguments, mainly for internal use
Optional session returned by metadataSweepCapture(). Its
complete variable description replaces dataDscr in codeBook, reusing
cached unweighted analysis. Study and document metadata remain supplied by
codeBook. Do not also supply data or variables. embed = TRUE includes
captured data with stable variable IDs; csv = TRUE requests a companion CSV.
Weighted export uses the existing weighted calculation path.
Current host revision, required when session is supplied.
Adrian Dusa
#' 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 finished XML is always validated against the bundled, pinned DDI Codebook
2.6 schema and its local dependencies before writing. Invalid or incomplete
documents, or unavailable schemas, cause an error. Validation failure leaves
the destination and any companion CSV unchanged, and writes nothing to an
output connection. No network access is needed for validation. 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.
Formatting and target line endings also apply when writing to a connection.
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