preprocess: Preprocess Data

preprocessR Documentation

Preprocess Data

Description

Preprocess data for analysis and visualization.

Usage

preprocess(
  x,
  config,
  dat_validation = NULL,
  dat_test = NULL,
  verbosity = 1L,
  ...
)

Arguments

x

Tabular data, i.e. data.frame, data.table, or tbl_df (tibble): Training set data to preprocess.

config

PreprocessorConfig: Preprocessing configuration created by setup_Preprocessor. May be omitted, in which case setup_Preprocessor arguments are passed directly via ....

dat_validation

Optional tabular data: Validation set data. Preprocessed using the values learned from the training set data.

dat_test

Optional tabular data: Test set data. Preprocessed using the values learned from the training set data.

verbosity

Integer: Verbosity level.

...

setup_Preprocessor arguments: Only used when config is not provided.

Details

preprocess() preprocesses training data and learns any data-dependent values (e.g. scale centers and coefficients, one-hot levels). Optional dat_validation and dat_test data are preprocessed using the values learned from the training data. To apply a trained Preprocessor to new data, use apply_preprocessor.

For interactive use, config may be omitted and setup_Preprocessor arguments passed directly instead, e.g. preprocess(x, scale = TRUE, center = TRUE). At least one preprocessing parameter must be specified: preprocess(x) is an error.

The preprocessed data comes back in the structure it was given – data.frame, data.table or tibble – and the object passed in is never modified. It carries no row names: a case identifier that matters belongs in a column, where it can be selected, joined, validated and serialized.

Value

Preprocessor object.

Author(s)

EDG

See Also

apply_preprocessor, setup_Preprocessor

Examples

# Setup a `Preprocessor`: this outputs a `PreprocessorConfig` object.
prp <- setup_Preprocessor(remove_duplicates = TRUE, scale = TRUE, center = TRUE)

# Includes a long list of parameters
prp

# Resample iris to get train and test data
res <- resample(iris, setup_KFold(seed = 2026))
iris_train <- iris[res[[1]], ]
iris_test <- iris[-res[[1]], ]

# Preprocess training data
iris_pre <- preprocess(iris_train, prp)

# Alternatively, for interactive use, pass `setup_Preprocessor()` arguments directly
iris_pre <- preprocess(iris_train, remove_duplicates = TRUE, scale = TRUE, center = TRUE)

# Access preprocessed training data with `preprocessed()`
preprocessed(iris_pre)

# Apply the same preprocessing to test data with `apply_preprocessor()`,
# which returns the preprocessed data directly.
# The scale and center values learned from the training data will be used.
iris_test_pre <- apply_preprocessor(iris_pre, iris_test)

rtemis documentation built on Oct. 20, 2026, 1:06 a.m.