This function allows you to identify queries by the use a specific expression. It can be used to identify missing values or to identify values that are outside the lower and upper limits of a variable.
Usage
rd_query(
...,
variables = NA,
expression = NA,
negate = FALSE,
event = NA,
filter = NA,
addTo = 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
)
Arguments
- ...
List containing the data, the dictionary and the event (if required). It may be the output of the `redcap_data` function.
- variables
Character vector of the names of the database variables to be checked.
- expression
Character vector of expressions to be applied to the selected variables.
- negate
Logical value which indicates whether the defined expression should be negated. Defaults to `FALSE`.
- event
The name of the REDCap event to be analyzed. If there are events in your REDCap project, you should use this argument in order to name the event to which the defined variables belong.
- filter
A filter to be applied to the dataset. For example, the branching logic of a determined variable can be applied using this argument.
- addTo
Data frame corresponding to a previous query data frame to which you can add the new query data frame. By default, the function always generates a new data frame without taking into account previous reports.
- variables_names
Character vector containing the description of each selected variable. By default, the function automatically takes the description of each variable from the dictionary of the REDCap project.
- query_name
Description of the query. It can be defined as the same one for all the variables, or you can define a different one for each variable. By default, the function defines it as `The value is [value] and it should not be [expression]'`.
- instrument
REDCap's instrument to which the variables belong. It can be defined as the same one for all the variables, or you can define a different one for each variable. By default, the function automatically selects the corresponding instrument of each variable from the dictionary of the REDCap project.
- report_title
Character string specifying the title of the report.
- report_zeros
Logical. If `TRUE`, the function returns a report containing variables with zero queries.
- by_dag
Logical. If `TRUE`, both elements of the output are grouped by the data access groups (DAGs) of the REDCap project.
- link
List containing project information used to create a web link to each query.
- data
Data frame containing the data read from REDCap. If the list is given, this argument is not required.
- dic
Data frame containing the dictionary read from REDCap. If the list is given, this argument is not required.
- event_form
Data frame containing the correspondence of each event with each form. If the list is specified this argument is not necessary.
Value
A list with a data frame of 9 columns (10 columns, if the link argument is specified) meant to help the user identify each query and a table with the total number of queries per variable.
Examples
# Missing values
example <- rd_query(covican,
variables = c("copd", "age"),
expression = c("is.na(x)", "x %in% NA"),
event = "baseline_visit_arm_1")
example
#> $queries
#> # A tibble: 11 × 9
#> Identifier DAG Event Instrument Field Repetition Description Query Code
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 100-58 Hospita… Base… Comorbidi… copd - Chronic ob… The … 100-…
#> 2 102-113 Hospita… Base… Demograph… age - Age The … 102-…
#> 3 105-11 Hospita… Base… Comorbidi… copd - Chronic ob… The … 105-…
#> 4 105-11 Hospita… Base… Demograph… age - Age The … 105-…
#> 5 105-56 Hospita… Base… Comorbidi… copd - Chronic ob… The … 105-…
#> 6 105-56 Hospita… Base… Demograph… age - Age The … 105-…
#> 7 112-15 Hospita… Base… Comorbidi… copd - Chronic ob… The … 112-…
#> 8 117-11 Hospita… Base… Comorbidi… copd - Chronic ob… The … 117-…
#> 9 117-11 Hospita… Base… Demograph… age - Age The … 117-…
#> 10 117-22 Hospita… Base… Comorbidi… copd - Chronic ob… The … 117-…
#> 11 117-22 Hospita… Base… Demograph… age - Age The … 117-…
#>
#> $results
#> <table class="table table-striped table-condensed" style="width: auto !important; margin-left: auto; margin-right: auto;">
#> <caption>Report of queries</caption>
#> <thead>
#> <tr>
#> <th style="text-align:center;border-bottom: 1px solid grey"> Variables </th>
#> <th style="text-align:center;border-bottom: 1px solid grey"> Description </th>
#> <th style="text-align:center;border-bottom: 1px solid grey"> Event </th>
#> <th style="text-align:center;border-bottom: 1px solid grey"> Query </th>
#> <th style="text-align:center;border-bottom: 1px solid grey"> Total </th>
#> </tr>
#> </thead>
#> <tbody>
#> <tr>
#> <td style="text-align:center;"> copd </td>
#> <td style="text-align:center;"> Chronic obstructive pulmonary disease </td>
#> <td style="text-align:center;"> Baseline visit </td>
#> <td style="text-align:center;"> The value should not be missing </td>
#> <td style="text-align:center;"> 6 </td>
#> </tr>
#> <tr>
#> <td style="text-align:center;"> age </td>
#> <td style="text-align:center;"> Age </td>
#> <td style="text-align:center;"> Baseline visit </td>
#> <td style="text-align:center;"> The value should not be missing </td>
#> <td style="text-align:center;"> 5 </td>
#> </tr>
#> </tbody>
#> </table>
# Expression
example <- rd_query(covican,
variables="age",
expression="x>20",
event="baseline_visit_arm_1")
example
#> $queries
#> # A tibble: 185 × 9
#> Identifier DAG Event Instrument Field Repetition Description Query Code
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 100-6 Hospita… Base… Demograph… age - Age The … 100-…
#> 2 100-13 Hospita… Base… Demograph… age - Age The … 100-…
#> 3 100-16 Hospita… Base… Demograph… age - Age The … 100-…
#> 4 100-31 Hospita… Base… Demograph… age - Age The … 100-…
#> 5 100-34 Hospita… Base… Demograph… age - Age The … 100-…
#> 6 100-36 Hospita… Base… Demograph… age - Age The … 100-…
#> 7 100-52 Hospita… Base… Demograph… age - Age The … 100-…
#> 8 100-58 Hospita… Base… Demograph… age - Age The … 100-…
#> 9 100-65 Hospita… Base… Demograph… age - Age The … 100-…
#> 10 100-66 Hospita… Base… Demograph… age - Age The … 100-…
#> # ℹ 175 more rows
#>
#> $results
#> <table class="table table-striped table-condensed" style="width: auto !important; margin-left: auto; margin-right: auto;">
#> <caption>Report of queries</caption>
#> <thead>
#> <tr>
#> <th style="text-align:center;border-bottom: 1px solid grey"> Variables </th>
#> <th style="text-align:center;border-bottom: 1px solid grey"> Description </th>
#> <th style="text-align:center;border-bottom: 1px solid grey"> Event </th>
#> <th style="text-align:center;border-bottom: 1px solid grey"> Query </th>
#> <th style="text-align:center;border-bottom: 1px solid grey"> Total </th>
#> </tr>
#> </thead>
#> <tbody>
#> <tr>
#> <td style="text-align:center;"> age </td>
#> <td style="text-align:center;"> Age </td>
#> <td style="text-align:center;"> Baseline visit </td>
#> <td style="text-align:center;"> The value should not be greater than 20 </td>
#> <td style="text-align:center;"> 185 </td>
#> </tr>
#> </tbody>
#> </table>
# Using the filter argument
example <- rd_query(covican,
variables = "potassium",
expression = "is.na(x)",
event = "baseline_visit_arm_1",
filter = "available_analytics=='1'")
#> Warning: The branching logic of the following variable was applied automatically: potassium
example
#> $queries
#> # A tibble: 21 × 9
#> Identifier DAG Event Instrument Field Repetition Description Query Code
#> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 102-6 Hospita… Base… Laborator… pota… - Potassium The … 102-…
#> 2 102-13 Hospita… Base… Laborator… pota… - Potassium The … 102-…
#> 3 102-23 Hospita… Base… Laborator… pota… - Potassium The … 102-…
#> 4 102-27 Hospita… Base… Laborator… pota… - Potassium The … 102-…
#> 5 102-30 Hospita… Base… Laborator… pota… - Potassium The … 102-…
#> 6 102-39 Hospita… Base… Laborator… pota… - Potassium The … 102-…
#> 7 102-48 Hospita… Base… Laborator… pota… - Potassium The … 102-…
#> 8 102-60 Hospita… Base… Laborator… pota… - Potassium The … 102-…
#> 9 102-64 Hospita… Base… Laborator… pota… - Potassium The … 102-…
#> 10 102-73 Hospita… Base… Laborator… pota… - Potassium The … 102-…
#> # ℹ 11 more rows
#>
#> $results
#> <table class="table table-striped table-condensed" style="width: auto !important; margin-left: auto; margin-right: auto;">
#> <caption>Report of queries</caption>
#> <thead>
#> <tr>
#> <th style="text-align:center;border-bottom: 1px solid grey"> Variables </th>
#> <th style="text-align:center;border-bottom: 1px solid grey"> Description </th>
#> <th style="text-align:center;border-bottom: 1px solid grey"> Event </th>
#> <th style="text-align:center;border-bottom: 1px solid grey"> Query </th>
#> <th style="text-align:center;border-bottom: 1px solid grey"> Total </th>
#> </tr>
#> </thead>
#> <tbody>
#> <tr>
#> <td style="text-align:center;"> potassium </td>
#> <td style="text-align:center;"> Potassium </td>
#> <td style="text-align:center;"> Baseline visit </td>
#> <td style="text-align:center;"> The value should not be missing </td>
#> <td style="text-align:center;"> 21 </td>
#> </tr>
#> </tbody>
#> </table>