rd_dictionary: Transform the data dictionary and handle branching logic

View source: R/rd_dictionary.R

rd_dictionaryR Documentation

Transform the data dictionary and handle branching logic

Description

[Stable]

Updates a REDCap data dictionary by converting branching logic and calculation expressions into valid R expressions. This ensures that conditional display rules and calculated fields in the dictionary can be programmatically evaluated with the dataset. Any variables that cannot be converted are reported in the results.

Usage

rd_dictionary(project = NULL, data = NULL, dic = NULL, event_form = NULL)

Arguments

project

A list containing the REDCap data, dictionary, and event mapping (expected redcap_data() output). Overrides data, dic, and event_form.

data

A data.frame or tibble with the REDCap dataset.

dic

A data.frame with the REDCap dictionary.

event_form

Only applicable for longitudinal projects (presence of events). Event-to-form mapping for longitudinal projects.

Details

The function performs the following tasks:

  • Evaluates and transforms branching logic expressions into valid R expressions using rd_rlogic.

  • Evaluates and converts calculation expressions for fields of type calc.

  • Keeps in REDCap syntax, with the codes of the options, the logic that uses as a number a variable already converted into a factor (e.g. ⁠[score] >= 3⁠ or ⁠[a] + [b]⁠ after rd_factor()): it can't be written as R logic of the factors. rd_rlogic() and rd_query() evaluate it with the codes, as REDCap does. The same happens with the logic that uses variables of other events.

  • Generates a results summary table listing any variables that could not be converted.

Value

A list with the following elements:

data

The original dataset passed to the function.

dictionary

The updated data dictionary with modified branching logic and calculations.

event_form

The original event-form mapping (if applicable).

results

A summary of the transformations, including any variables with unconverted branching logic.

See Also

Other process functions: rd_checkbox(), rd_dates(), rd_delete_vars(), rd_factor(), rd_insert_na(), rd_recalculate(), rd_rlogic(), rd_split(), rd_transform()

Examples

## Not run: 
result <- rd_dictionary(covican)
print(result$results)
updated_dic <- result$dictionary

## End(Not run)


REDCapDM documentation built on Nov. 27, 2026, 9:06 a.m.