Transforms the raw REDCap data read by the redcap_data function. The function runs in one-step pipeline the functions dedicated to processing the data (rd_delete_vars(), rd_dates(), rd_recalculate(), rd_checkbox(), rd_factor(), rd_dictionary() and, with final_format, rd_split()) and returns the transformed data and dictionary, along with a summary of each step done. rd_insert_na() is not part of it: its filters are specific to each project, so apply it separately.
Usage
rd_transform(
project = NULL,
data = NULL,
dic = NULL,
event_form = NULL,
checkbox_labels = c("No", "Yes"),
na_logic = "none",
exclude_recalc = NULL,
exclude_factor = NULL,
delete_vars = NULL,
delete_pattern = NULL,
final_format = "raw",
which_event = NULL,
which_form = NULL,
wide = NULL
)Arguments
- project
A list containing the REDCap data, dictionary, and event mapping (expected
redcap_data()output). Overridesdata,dic, andevent_form.- data
A
data.frameortibblewith the REDCap dataset.- dic
A
data.framewith the REDCap dictionary.- event_form
Only applicable for longitudinal projects (presence of events). Event-to-form mapping for longitudinal projects.
- checkbox_labels
Character vector of length 2 for labels of unchecked/checked values. Default:
c("No", "Yes").- na_logic
Controls how missing values are set based on the branching logic of a checkbox. Must be one of
"none"(do nothing),"missing"(set toNAonly when the logic evaluation isNA), or"eval"(set toNAwhen the logic evaluates toFALSEorNA). Defaults to"none".- exclude_recalc
Optional. Character vector of field names to exclude from recalculation.
- exclude_factor
Optional character vector of variable names (use original names without the
.factorsuffix) to exclude from conversion.- delete_vars
Optional. A character vector of variable names to remove from both the dataset and dictionary.
- delete_pattern
Optional. A character vector of regular expression patterns. Variables matching these patterns will be removed from the dataset and dictionary.
- final_format
Character string indicating the final format of the data. Options are
raw,by_eventorby_form.raw(default) returns the transformed data in its original structure,by_eventreturns it as a nested data frame by event, andby_formreturns it as a nested data frame by form.- which_event
Character. If
final_format = "by_event", return only this event.- which_form
Character. If
final_format = "by_form", return only this form.- wide
Logical. If
TRUE(for form-based splits), repeated instances are returned in wide format. Defaults toFALSE.
Value
A list with elements:
- data
Transformed data. With
final_format = "by_event"or"by_form", as inrd_split(): a tibble with one row per event or form and its dataset in the list-columndf(e.g.trans$data$df[[1]]), or thedata.frameof the event or form chosen withwhich_eventorwhich_form.- dictionary
Updated dictionary data.frame.
- event_form
Event–form mapping (if applicable).
- results
Character summary of transformation steps performed.
See also
Other process functions:
rd_checkbox(),
rd_dates(),
rd_delete_vars(),
rd_dictionary(),
rd_factor(),
rd_insert_na(),
rd_recalculate(),
rd_rlogic(),
rd_split()
Examples
# Minimal usage (project object or data + dictionary)
trans <- rd_transform(covican)
#> ⏳ Transformation in progress...
#> All date and datetime variables are already in the correct format. No
#> transformation applied.
# Custom checkbox labels
trans <- rd_transform(covican,
checkbox_labels = c("Not present", "Present"))
#> ⏳ Transformation in progress...
#> All date and datetime variables are already in the correct format. No
#> transformation applied.
# Return only a single form (wide)
trans <- rd_transform(covican,
final_format = "by_form",
which_form = "laboratory_findings",
wide = TRUE)
#> ⏳ Transformation in progress...
#> All date and datetime variables are already in the correct format. No
#> transformation applied.
