| rd_checkbox | R Documentation |
This function is used to process checkbox variables in a REDCap dataset. By default, it changes their default categories ("Unchecked" and "Checked") to new ones ("No" and "Yes). Optionally, the function can also evaluate the branching logic for checkbox fields and adjust the data and dictionary accordingly.
rd_checkbox(
project = NULL,
data = NULL,
dic = NULL,
event_form = NULL,
checkbox_labels = c("No", "Yes"),
checkbox_names = TRUE,
na_logic = "missing"
)
project |
A list containing the REDCap data, dictionary, and event mapping (expected |
data |
A |
dic |
A |
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: |
checkbox_names |
Logical. If |
na_logic |
Controls how missing values are set based on branching logic. Must be one of |
Checkbox columns are expected in REDCap wide format (field___code).
Branching logic evaluation requires event_form for longitudinal projects.
Names are cleaned and truncated to 60 characters; uniqueness is enforced.
Fields that cannot be evaluated are listed in results.
In the branching logic and calculations, the options get their new names and keep their codes 0 and 1, as in REDCap logic (e.g. [cb(1)] = '1' is [cb_option] = '1', and [cb(1)] + [cb(2)] >= 2 is [cb_option] + [cb_other] >= 2). rd_dictionary() writes the labels when it translates the logic into R.
A list with:
Transformed dataset with the checkbox options optionally renamed. When the data has the .factor
versions of the options, the original columns keep their codes 0/1 and the .factor versions take the labels of
checkbox_labels; otherwise the original columns are replaced by factors with these labels.
Updated dictionary with checkbox fields expanded and optionally renamed.
The event_form passed in (if applicable).
Summary of transformations and any fields needing review.
Other process functions:
rd_dates(),
rd_delete_vars(),
rd_dictionary(),
rd_factor(),
rd_insert_na(),
rd_recalculate(),
rd_rlogic(),
rd_split(),
rd_transform()
# Basic usage with a project object
res <- rd_checkbox(covican)
# With custom labels
res <- rd_checkbox(data = covican$data,
dic = covican$dictionary,
event_form = covican$event_form,
checkbox_labels = c("Not present", "Present"))
# Keep original checkbox names
res <- rd_checkbox(covican, checkbox_names = FALSE)
# Longitudinal project with NA logic
res <- rd_checkbox(data = covican$data,
dic = covican$dictionary,
event_form = covican$event_form,
na_logic = "eval")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.