Skip to contents

Creates a subset of the main REDCap database (`DB`) based on specific filter criteria and saves it to a specified directory. The subset can be further customized with additional forms, fields, and deidentification options.

Usage

add_DB_subset(
  DB,
  subset_name,
  filter_field,
  filter_choices,
  dir_other = file.path(DB$dir_path, "output"),
  file_name = paste0(DB$short_name, "_", subset_name),
  form_names = NULL,
  field_names = NULL,
  deidentify = T,
  force = F
)

Arguments

DB

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

subset_name

Character. The name of the subset to create.

filter_field

Character. The name of the field in the database to filter on.

filter_choices

Vector. The values of `filter_field` used to define the subset.

dir_other

Character. The directory where the subset file will be saved. Default is the `output` folder within the database directory.

file_name

Character. The base name of the file where the subset will be saved. Default is `<DB$short_name>_<subset_name>`.

form_names

Character vector. Names of forms to include in the subset. Default is `NULL`, which includes all forms.

field_names

Character vector. Names of specific fields to include in the subset. Default is `NULL`, which includes all fields.

deidentify

Logical. Whether to deidentify the data in the subset. Default is `TRUE`.

force

Logical. If `TRUE`, overwrite existing subset files with the same name. Default is `FALSE`.

Value

A modified `DB` object that includes the newly created subset. The subset is also saved as a file in the specified directory.

Details

This function filters the main REDCap database using the specified `filter_field` and `filter_choices`, then creates a new subset with optional deidentification. It can be customized to include only specific forms or fields. The resulting subset is saved to a file for future use.

See also

save_DB for saving the main database or subsets.