step_line_intensities: Emission Line Intensities Recipe Step

View source: R/line_intensities.R

step_line_intensitiesR Documentation

Emission Line Intensities Recipe Step

Description

step_line_intensities() creates a specification of a recipe step that replaces the spectral columns by the intensities of selected emission lines, measured with line_intensities().

Usage

step_line_intensities(
  recipe,
  ...,
  lines,
  half_width = 0.15,
  search = 0.2,
  method = "area",
  baseline = FALSE,
  prefix = "line_",
  keep_original_cols = FALSE,
  role = "predictor",
  trained = FALSE,
  columns = NULL,
  skip = FALSE,
  id = recipes::rand_id("line_intensities")
)

Arguments

recipe

A recipe object. The step will be added to the sequence of operations for this recipe.

...

One or more selector functions to choose the predictors (for example, the spectral channels). See recipes::selections().

lines

The lines: a numeric vector of wavelengths (nm), preferably named, such as c(Ca = 393.37, Mg = 279.55).

half_width

The half-width of the integration window around the peak, in nm. Default is 0.15.

search

The half-width of the window in which the peak is searched around the tabulated wavelength, in nm. Default is 0.2.

method

"area" (default) or "height".

baseline

A logical: subtract a linear baseline under each line (FALSE, default).

prefix

The prefix of the new column names. Default is "line_".

keep_original_cols

A logical: keep the spectral columns (FALSE, default).

role

Not used by this step, since no new variables are created.

trained

A logical indicating whether the step has been trained.

columns

The names of the selected columns, stored once the step has been trained.

skip

A logical. Should the step be skipped when the recipe is baked by recipes::bake()? Keep the default FALSE, so that new data are corrected with the same filter as the training data.

id

A character string that is unique to this step.

Details

The selected columns form one spectrum per row, and their names must be their wavelengths (in nm). Each line becomes a new column, named by prefix and the name of the line (or its wavelength). Nothing is estimated from the training data. The Voigt method of line_intensities() is not offered, as it is too slow for resampling. tidy() returns the line names, their wavelength, the method and id.

Value

An updated version of recipe with the new step added to the sequence of existing steps.

See Also

line_intensities(), step_line_ratio()

Examples

if (rlang::is_installed("recipes")) {
  data(forageLIBS)
  rec <- recipes::recipe(K ~ ., data = forageLIBS[-c(1:10, 12:14)]) |>
    step_line_intensities(recipes::all_predictors(),
                          lines = c(K = 769.90, Mg = 285.21, Ca = 317.93)) |>
    recipes::prep()
  head(recipes::bake(rec, new_data = NULL))
}

specProc documentation built on Nov. 20, 2026, 5:11 p.m.