Learn R Programming

functionals (version 0.5.0)

fcv: Functional Cross-Validation mapping

Description

Applies a user-defined function `.f` to each element of `.splits`, typically from cross-validation objects such as `rsample::vfold_cv()`.

Usage

fcv(.splits, .f, ncores = NULL, pb = FALSE, ...)

Value

A list of results returned by applying `.f` to each element of `.splits`.

Arguments

.splits

A list of resample splits (e.g., from `rsample::vfold_cv()`).

.f

A function to apply to each split. Typically expects a single `split` object.

ncores

Integer. Number of cores to use for parallel processing. Default is `NULL` (sequential).

pb

Logical. Whether to display a progress bar. Default is `FALSE`.

...

Additional arguments passed to `.f`.

Examples

Run this code
if (requireNamespace("rsample", quietly = TRUE)) {
  set.seed(123)
  cv_splits <- rsample::vfold_cv(mtcars, v = 5)

  # Apply summary over training sets
  fcv(cv_splits$splits, function(split) {
    summary(rsample::analysis(split))
  })

  # With progress and parallel execution
  # \donttest{
    fcv(cv_splits$splits, function(split) {
      summary(rsample::analysis(split))
    }, ncores = 2, pb = TRUE)
  # }
}

Run the code above in your browser using DataLab