Learn R Programming

REDCapDM (version 1.0.1)

rd_split: Split a REDCap dataset by form or event

Description

[Experimental]

Splits a REDCap dataset into separate datasets by form or event using the data dictionary. Supports both longitudinal and non-longitudinal projects and can return wide or long formats for repeated measures.

Usage

rd_split(
  project = NULL,
  data = NULL,
  dic = NULL,
  event_form = NULL,
  which = NULL,
  by = "form",
  wide = FALSE
)

Value

Depending on which and wide:

data

A data.frame or a list of data.frames representing the split datasets.

dictionary

The original REDCap dictionary.

event_form

The original event-form mapping (if applicable).

results

A summary message of the splitting operation.

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.

which

Optional. A single form or event to extract. If not provided, all forms or events are returned.

by

Character. Criteria to split the dataset: "form" (default) or "event".

wide

Logical. If TRUE (for form-based splits), repeated instances are returned in wide format. Defaults to FALSE.

Details

  • Handles checkbox variables and REDCap default variables (_complete, _timestamp) appropriately.

  • For form-based splits in longitudinal projects, uses event_form to map variables to events.

  • Wide format expands repeated instances into multiple columns per record.

  • Filtering by which allows extracting a single form or event.

  • Projects with repeated instruments are handled by filtering on the redcap_repeat_instrument variable.

Examples

Run this code
# Split by form and return wide format
result <- covican |>
  rd_split(by = "form", wide = TRUE)

print(result)

# Split by event (long format)
result <- covican |>
  rd_split(by = "event")

print(result)

Run the code above in your browser using DataLab