measure_map() applies a function to each sample's measurement data.
This function is intended for exploration and prototyping, not for
production pipelines. For reproducible preprocessing, use
step_measure_map() instead.
Usage
measure_map(
.data,
.f,
.cols = NULL,
...,
verbosity = 1L,
.error_call = rlang::caller_env()
)Arguments
- .data
A data frame containing one or more
measure_listcolumns.- .f
A function or formula to apply to each sample's measurement tibble.
If a function, it is used as-is.
If a formula (e.g.,
~ { .x$value <- log(.x$value); .x }), it is converted to a function usingrlang::as_function().
- .cols
<
tidy-select> Columns to apply the transformation to. Defaults to allmeasure_listcolumns.- ...
Additional arguments passed to
.f.- verbosity
An integer controlling output verbosity:
0: Silent - suppress all messages and output from.f1: Normal (default) - show output from.f
- .error_call
The execution environment for error reporting.
Details
Intended Use: Exploration, Not Production
This function is designed for interactive exploration and debugging:
# Good: Prototyping a new transformation
baked_data |>
measure_map(~ { .x$value <- my_experimental_fn(.x$value); .x })
# Better: Once it works, put it in a recipe step
recipe(...) |>
step_measure_map(my_experimental_fn) |>
prep()Unlike recipe steps, transformations applied with measure_map() are NOT:
Automatically applied to new data
Bundled into workflows
Reproducible across sessions
See also
step_measure_map()for production use in recipe pipelinesmeasure_map_safely()for fault-tolerant explorationmeasure_summarize()for computing summary statistics
Examples
library(recipes)
# First, get data in internal format
rec <- recipe(water + fat + protein ~ ., data = meats_long) |>
update_role(id, new_role = "id") |>
step_measure_input_long(transmittance, location = vars(channel)) |>
prep()
baked_data <- bake(rec, new_data = NULL)
# Explore a custom transformation
result <- measure_map(baked_data, ~ {
# Subtract the minimum value from each spectrum
.x$value <- .x$value - min(.x$value)
.x
})
# Once you're happy with it, use step_measure_map() in your recipe:
# recipe(...) |>
# step_measure_map(~ { .x$value <- .x$value - min(.x$value); .x })