Learn R Programming

DDIwR (version 0.19)

DDI-children: Add/remove/change one or more children or attributes from a DDI Codebook attribute.

Description

addChildren() adds one or more children to a standard DDI Codebook element (see makeElement), anyChildren() checks if an element has any children at all, hasChildren() checks if the element has specific children, indexChildren() returns the positions of the children among all containing children, and getChildren() extracts them. For attributes and content, there are dedicated functions to add*(), remove*() and change*().

Usage

addChildren(children, to, overwrite = TRUE, ...)

anyChildren(element)

getChildren(xpath, from, ...)

hasChildren(element, name)

indexChildren(element, name)

removeChildren(name, from, overwrite = TRUE, ...)

addContent(content, to, overwrite = TRUE)

changeContent(content, to, overwrite = TRUE)

removeContent(from, overwrite = TRUE)

addAttributes(attrs, to, overwrite = TRUE)

anyAttributes(element)

changeAttributes(attrs, from, overwrite = TRUE)

hasAttributes(element, name)

removeAttributes(name, from, overwrite = TRUE)

Value

An invisible standard DDI element. Functions any*() and has*()

return a logical (vector).

Arguments

children

A standard element of class "DDI", or a list of such elements.

to

A standard element of class "DDI".

overwrite

Logical, overwrite the original object in the parent frame.

...

Other arguments, mainly for internal use.

element

A standard element of class "DDI".

xpath

Character, a path to a DDI Codebook element.

from

A standard element of class "DDI".

name

Character, name(s) of specific child element / attribute.

content

Character, the text content of a DDI element.

attrs

A list of specific attribute names and values.

Author

Adrian Dusa

Details

Although an XML list generally allows for multiple contents, sometimes spread between the children elements, it is preferable to maintain a single content (eventually separated with carriage return characters for separate lines).

Arguments are unique, and can be changed by simply referring to their names.

Elements, however, can be repeated. For instance element var to describe variables, within the dataDscr (data description) sub-element in the codeBook. There are as many such var elements as the number of variables in the dataset, in which case it is not possible to change a specific var element by referring to its name. For this purpose, it is useful to extract the positions of all var elements to iterate through, which is the purpose of the function indexChildren().

Future versions will allow deep manipulations of child elements using the xpath argument.

If more than one children, they should be grouped into a list.