Skip to contents

`spec_values_at()` extracts spectral values at specified wavenumber positions. The function finds the closest wavenumber matches and returns the corresponding spectral intensities for each sample column.

Usage

spec_values_at(
  spec_data,
  wn_values,
  wn_col = NULL,
  method = "closest",
  tolerance = Inf,
  format = "wide"
)

Arguments

spec_data

A tibble containing spectral data

wn_values

Numeric vector of wavenumber values to extract

wn_col

Character string specifying the wavenumber column name. If NULL, uses the globally set wavenumber column from `set_spec_wn()`.

method

Character string specifying the extraction method. Options: "closest" (default), "exact", "interpolate". See Details.

tolerance

Numeric value specifying the maximum allowed difference for "closest" method. Default: Inf (no limit).

format

Character string specifying output format. Options: "wide" (default), "long". See Details.

Value

A tibble with extracted values in the specified format

Details

Extraction methods: - "closest": Find the closest wavenumber match (default) - "exact": Only return exact matches (NA for non-matches) - "interpolate": Use linear interpolation between adjacent points

Output formats: - "wide": Each wavenumber becomes a row, samples as columns - "long": Tidy format with wavenumber, sample, and value columns

Examples

if (FALSE) { # \dontrun{
# Set wavenumber column
set_spec_wn("Wavenumber")

# Extract values at specific wavenumbers
peaks <- c(1650, 1450, 1250, 1050)
extracted <- spec_values_at(CoHAspec, peaks)

# Use exact matching only
extracted <- spec_values_at(CoHAspec, peaks, method = "exact")

# Get results in long format
extracted <- spec_values_at(CoHAspec, peaks, format = "long")

# Use interpolation
extracted <- spec_values_at(CoHAspec, peaks, method = "interpolate")
} # }