Skip to contents

This function filters the records in the `DB` object by specified criteria, such as field names, form names, and optional filtering based on a specific field and its values. It returns a modified `DB` object containing only the records that match the filter criteria.

Usage

filter_DB(
  DB,
  filter_field,
  filter_choices,
  form_names,
  field_names,
  warn_only = F,
  no_duplicate_cols = F
)

Arguments

DB

A validated `DB` object containing REDCap project data and settings. Generated using load_DB or setup_DB

filter_field

A character string representing an extra variable name to be filtered by. This field must be present in the data frame.

filter_choices

A character vector of values to filter by for the `filter_field`. Only records with these values in the specified field will be included.

form_names

A character vector of form names to be included in the filtered data. If missing, all forms are included.

field_names

A character vector of field names to be included in the filtered data. If missing, all fields are included.

warn_only

A logical flag (`TRUE` or `FALSE`). If `TRUE`, the function will issue a warning instead of stopping if the filtering criteria do not match any records. Defaults to `FALSE`.

no_duplicate_cols

A logical flag (`TRUE` or `FALSE`). If `TRUE`, the function will avoid including duplicate columns in the output. Defaults to `FALSE`.

Value

A modified `DB` object with filtered records and columns based on the provided criteria.

Details

This function filters the data in the `DB` object according to the specified form and field names and optional filter criteria. If no field names or form names are provided, it defaults to using all fields and forms in the database. The function uses the helper `filter_DF_list` to apply the filtering logic to the `DB$data` list.