| rd_insert_na | R Documentation |
Sets selected variables to NA when a filter condition is satisfied. Useful for managing checkboxes or other fields without explicit gatekeeper questions.
rd_insert_na(
project = NULL,
data = NULL,
dic = NULL,
event_form = NULL,
vars,
filter
)
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. |
vars |
Character vector of variable names to set to |
filter |
A single logical expression (as string). Rows where the filter evaluates to |
Each variable is only updated in rows/events where both the variable and filter are present.
If the variable has a .factor version, it is updated too.
For longitudinal projects, event_form must be provided for proper event-level filtering.
Only one filter expression is allowed.
The columns of the filter must be known to check their events: use their names (e.g. age > 30), data$age, data[["age"]], .data[[field]], data[, "age"] or data[, 3]. A filter that uses the data in another way (e.g. dplyr::pull(data, "age") or rev(data)[, 2]), finds objects by their name or evaluates code (e.g. get("age") or eval(parse(text = "age"))), or whose result depends on other columns of the data (e.g. through a function of your session that reads them) stops with an error.
Variables and filter columns must exist in both data and dictionary: their .factor and _mdc versions and the options of a checkbox (e.g. cb___1) are checked with their field. The objects of your session used in the filter don't need to be in them.
A list with:
The dataset with NA inserted where the filter applies.
The unchanged dictionary.
The event_form passed in (if applicable).
Summary message of the changes applied.
Other process functions:
rd_checkbox(),
rd_dates(),
rd_delete_vars(),
rd_dictionary(),
rd_factor(),
rd_recalculate(),
rd_rlogic(),
rd_split(),
rd_transform()
# Set 'potassium' to NA where age < 65
result <- rd_insert_na(
covican,
vars = "potassium",
filter = "age < 65"
)
table(is.na(result$data$potassium))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.