Learn R Programming

REDCapDM (version 1.0.1)

rd_recalculate: Recalculate and Verify Calculated Fields in REDCap Data

Description

[Experimental]

Recalculates fields marked as calculated in the REDCap dictionary, compares them with the original values, and reports discrepancies. If any differences are found, new recalculated fields are added to the dataset and dictionary with _recalc appended to the names.

Usage

rd_recalculate(
  project = NULL,
  data = NULL,
  dic = NULL,
  event_form = NULL,
  exclude = NULL
)

Value

A list with:

data

The dataset with new _recalc fields for any differing calculated fields.

dictionary

Updated dictionary including the new _recalc fields.

event_form

The event_form passed in (if applicable).

results

Summary report of the recalculation process, including tables of discrepancies.

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.

exclude

Optional. Character vector of field names to exclude from recalculation.

Details

  • Fields of type calc in the dictionary are recalculated.

  • Recalculated values are compared with the original values.

  • If differences exist, new fields [field_name]_recalc are added to the dataset and dictionary.

  • Works for single-event projects; for longitudinal projects, event_form must be provided.

  • Fields with incomplete branching logic or smart variables may fail to recalculate.

Examples

Run this code
# Recalculate all calculated fields
if (FALSE) {
results <- rd_recalculate(
  data = covican$data,
  dic = covican$dictionary,
  event_form = covican$event_form
)
}

# Recalculate but exclude some variables
if (FALSE) {
results <- rd_recalculate(
  project = covican,
  exclude = c("age", "screening_fail_crit")
)
}

Run the code above in your browser using DataLab