Skip to contents

This function cleans the columns of a `DB` object, transforming choice fields into factors and ensuring numeric columns are set correctly for table processing or plotting (e.g., using `table1`). It handles the transformation of missing values and optional removal of certain codes based on user input.

Usage

clean_DB(DB, drop_blanks = F, other_drops = NULL)

Arguments

DB

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

drop_blanks

Logical. If TRUE, will drop choice fields with zero occurrences (n = 0). Default is FALSE.

other_drops

A list of additional fields or choices to drop from the data. Defaults to NULL.

Value

A cleaned `DB` object ready for table or plot processing.

Details

The function works by cleaning up the data frame list (`DB$data`) according to the metadata (`DB$metadata$fields`). It converts choice fields into factors, numeric fields are treated appropriately, and any unwanted or missing codes can be dropped based on the parameters provided. The function also ensures that the data is only cleaned once by checking the internal `is_clean` flag.

Note

The function will not proceed with cleaning if `DB$internals$is_clean` is already TRUE, signaling that the DB has already been cleaned.