Architecture
Internal design of the classbound package
The classbound package is built around a robust, extensible pipeline leveraging R's S3 object system. The primary goal is to decouple the core boundary computation and visualization logic from the idiosyncrasies of specific modeling packages.
The Core Pipeline
The user-facing workflow consists of four steps. Data validation and metadata extraction happen centrally in fit_model, and the results flow through the pipeline.
The Adapter Pattern (S3 Dispatch)
To support multiple classifiers natively, the core pipeline never calls specific model algorithms directly. Instead, fit_model and predict_model act as wrappers around internal S3 generics: fit_adapter and predict_adapter.
This allows user-defined classifiers to plug into the pipeline automatically simply by defining these two methods in the global environment, without requiring any changes to the classbound source code.
Data Validation Contract
Initially, individual adapters handled their own factor conversions and missing value checks. This led to code duplication. Now, preprocess_data() centralizes all factor handling, NA rejection, tibble coercion, and validation.
Adapters assume the input is clean. In return, adapters must fulfill a strict output contract: predict_adapter must return exactly a list structure: list(class = ..., probs = ...). If the model does not support probabilities (e.g., PPtreeExt), it must return probs = NULL.
predict_model() then intercepts this output and strictly enforces that the class factor levels match the exact levels observed during fit_model(). This guarantees that multi-model comparison workflows retain consistent color mappings, even if one model was trained on a subset of the data that lacked a certain class.