Learn R Programming

bioLeak (version 0.2.0)

.guard_ensure_levels: Ensure consistent categorical levels for guarded preprocessing

Description

Converts character/logical columns to factors and aligns factor levels with a training-time levels_map. Adds a dummy level when a column has only one observed level so that downstream one-hot encoding retains a column.

Usage

.guard_ensure_levels(df, levels_map = NULL, dummy_prefix = "__dummy__")

Value

List with elements data (data.frame) and levels (named list of levels).

Arguments

df

data.frame to normalize factor levels.

levels_map

optional named list of factor levels learned from training data.

dummy_prefix

prefix used when adding a dummy level to single-level factors.