The preprocess_recipe function assembles an ordered sequence of
preprocessing steps into a recipe, while process executes the
recipe on a spectral data matrix.
Arguments
- ...
one or more objects of class
preprocessingas returned by any of the following constructor functions:The order in which the objects are provided defines the order of execution. If no arguments are provided, an empty recipe is returned and
processwill return the input data unchanged.- device
a character string specifying the target device:
"unspecified"(no validation),"proximate", or"proxiscout". When"proximate"or"proxiscout"is specified,preprocess_recipevalidates that all steps are compatible with that device and raises an informative error if not. Pass"unspecified"to skip validation explicitly.deviceis required whenever the recipe contains any preprocessing step, with one exception: a recipe containing only a singleprep_snvstep does not requiredevice, because SNV is device-agnostic (identical behaviour for both"proximate"and"proxiscout"). In that casedevicedefaults to"unspecified".- X
a numeric matrix of spectral data to be preprocessed (samples in rows, wavelengths in columns).
- recipe
an object of class
preprocess_recipeas returned bypreprocess_recipe. A single object of classpreprocessingis also accepted and treated as a one-step recipe.
Value
For preprocess_recipe, an object of class preprocess_recipe with
three components: steps (the ordered list of preprocessing step
objects), device (the target device string), and
preprocessing_order (a simplified string summarising the
sequence of applied transformations).
For process, a numeric matrix of preprocessed spectral data. The
applied recipe is stored as the attribute "preprocess_recipe" on the
returned matrix and can be retrieved with
attr(result, "preprocess_recipe").
Examples
data("NIRcannabis")
X <- NIRcannabis$spc
# SNV alone — no device needed (SNV is device-agnostic)
recipe_snv <- preprocess_recipe(prep_snv())
X_snv <- process(X, recipe_snv)
# Any other combination requires device
recipe <- preprocess_recipe(
prep_smooth(w = 7, p = 1, algorithm = "savitzky-golay"),
prep_snv(),
prep_derivative(m = 1, w = 5, p = 2, algorithm = "savitzky-golay"),
device = "proxiscout"
)
X_proc <- process(X, recipe)
attr(X_proc, "preprocess_recipe")
#> Spectral preprocessing recipe (device: "proxiscout"):
#> - Step 1: prep_smooth
#> w: 7; p: 1; algorithm: 'savitzky-golay'
#> - Step 2: prep_snv
#> - Step 3: prep_derivative
#> m: 1; w: 5; p: 2; algorithm: 'savitzky-golay'
