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

DDI-childrenR Documentation

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)

makePath(xpath, from, overwrite = TRUE, ...)

moveChild(xpath, from, to, overwrite = TRUE, ...)

replaceChild(xpath, with, 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)

Arguments

children

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

to

A standard element of class "DDI", or an xpath string pointing to a target element.

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, an xpath to a DDI Codebook element. Indexed segments are supported using square brackets, e.g. codeBook/dataDscr/var[3]. Missing indexes default to the first matching element.

from

A standard element of class "DDI", or an xpath string pointing to a target element.

name

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

content

Character, the text content of a DDI element.

with

A standard element of class "DDI", or an xpath string pointing to a target element.

attrs

A list of specific attribute names and values.

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). XPath resolution accepts indexed segments using ⁠[n]⁠. When an index is missing, the first matching element is selected.

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

Elements can be repeated. For example, dataDscr contains one var element per dataset variable. When multiple var elements exist, referring only to the name is ambiguous. Use indexed xpaths like var[3] to target a specific instance, or use indexChildren() to list all positions for iteration.

If more than one children, they should be grouped into a list. Functions addContent, changeContent, removeContent, addAttributes, changeAttributes, and removeAttributes accept either a standard DDI element or a character xpath. When an xpath is provided, the target element is resolved and replaced in the root element.

Value

An invisible standard DDI element. Functions ⁠any*()⁠ and ⁠has*()⁠ return a logical (vector).

Author(s)

Adrian Dusa


DDIwR documentation built on Aug. 22, 2026, 9:07 a.m.

Related to DDI-children in DDIwR...