| rd_query | R Documentation |
Detects and summarizes queries in a REDCap dataset based on specified expressions, filters, or a defined branching logic. Useful for identifying missing values, out-of-range values, or values that do not meet predefined criteria.
rd_query(
project = NULL,
variables = NA,
expression = NA,
negate = FALSE,
event = NA,
filter = NA,
add_to = NA,
variables_names = NA,
query_name = NA,
instrument = NA,
report_title = NA,
report_zeros = FALSE,
by_dag = FALSE,
link = list(),
data = NULL,
dic = NULL,
event_form = NULL,
addTo = deprecated()
)
project |
A list containing the REDCap data, dictionary, and event mapping (expected |
variables |
Character vector of variable names to check for queries. |
expression |
Character vector of R conditions, written as text, to evaluate for each variable, where |
negate |
Logical, if |
event |
REDCap event(s) to analyze in longitudinal projects. If it isn't given, the events where the form of each variable is collected are taken from |
filter |
Optional filter of the rows to check, written as text (e.g. |
add_to |
Optional output of a previous |
variables_names |
Optional character vector of descriptions for each variable. Defaults to the variables labels in the dictionary. |
query_name |
Optional character vector describing each query. Defaults to a standard format: |
instrument |
Optional REDCap instrument(s) for each variable. Defaults to the instrument reported in the dictionary. |
report_title |
Optional string specifying the title of the final report. Defaults to |
report_zeros |
Logical, include variables with zero queries in the report. Default is |
by_dag |
Logical, split results by Data Access Group (DAG). Default is |
link |
Optional list containing project information ( |
data |
A |
dic |
A |
event_form |
Only applicable for longitudinal projects (presence of events). Event-to-form mapping for longitudinal projects. |
addTo |
The function performs the following steps:
Applies user-specified expressions to the selected variables to detect queries.
Optionally negates the expressions to find values that do not satisfy the condition.
Handles REDCap branching logic, converting it into R-compatible expressions for evaluation.
Applies additional user-specified filters before identifying queries.
Generates structured query results with metadata including:
Identifier: the record identifier, record_id or else the first field of the dictionary (e.g. subject_id), whatever its position in the data. Filters and expressions can use it by its name.
DAG (if present)
Event (the unique event name, e.g. baseline_arm_1), EventLabel (its label, e.g. Baseline (Arm 1: Drug A)) and Instrument
Field, Repetition, Description, Query statement
Optional link to REDCap entry
Optionally combines results with previous query outputs using add_to. The event of a query is its unique event
name: a label can be renamed in REDCap or be the same in several arms. The previous queries take the current label
of their events.
Produces a summarized report, optionally including variables with zero queries.
If branching logic cannot be translated by rd_rlogic(), the function warns and checks the variable without applying that branching logic. Review these queries manually or provide an appropriate filter.
A list of class REDCapDM_report, which prints a short summary (see print.REDCapDM_report()), containing:
A data frame or a list of data frames (if by_dag = TRUE, one per DAG) with detailed query information for each record.
A formatted report (HTML table) summarizing total queries per variable and event; with by_dag = TRUE, a list with one table per DAG.
Other query functions:
check_queries(),
rd_event(),
rd_export()
## Not run:
# Identify missing values for multiple variables
result <- rd_query(covican,
variables = c("copd", "age"),
expression = c("is.na(x)", "x %in% NA"),
event = "baseline_visit_arm_1"
)
result$results
# Identify values exceeding a threshold
result <- rd_query(covican,
variables = "age",
expression = "x > 20",
event = "baseline_visit_arm_1"
)
# Apply a filter to select subset of data
result <- rd_query(covican,
variables = "potassium",
expression = "is.na(x)",
event = "baseline_visit_arm_1",
filter = "available_analytics == '1'"
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.