validate_columns {matriz} | R Documentation |
Validate and Clean Imported Data Matrix
Description
This function ensures that the imported data contains all required columns, optionally removes unwanted extra columns, and provides informative messages about the dataset's structure.
Usage
validate_columns(
data,
extra_columns = NULL,
drop_extra = FALSE,
silent = FALSE
)
Arguments
data |
A data frame containing the imported matrix. |
extra_columns |
A character vector of allowed additional columns beyond the required ones. Defaults to NULL. |
drop_extra |
A logical value indicating whether to remove extra columns that are not in 'extra_columns'. Defaults to FALSE. |
silent |
A logical value indicating whether to suppress messages. Defaults to FALSE. |
Details
The function checks whether all required columns are present in the data. If any required columns are missing, it stops execution and informs the user.
It also identifies extra columns beyond the required set and compares them against the allowed 'extra_columns'. If 'drop_extra = TRUE', it removes any extra columns not listed in 'extra_columns'. If 'drop_extra = FALSE', it retains the extra columns but issues a message unless 'silent = TRUE'.
Value
A cleaned data frame with required columns intact and, optionally, extra columns removed.
Note
The function assumes that column names in 'data' are correctly formatted and case-sensitive.