Skip to content

feature request: add finalization method for workflow setsΒ #164

@jkylearmstrong

Description

@jkylearmstrong

I think it would be helpful to add a function to finalize all the workflows, so far something like this seems to work pretty well

#' Finalize Parameter Grid for a Single Workflow
#'
#' @param workflow_id workflow id
#' @param workflow_sets workflow sets
#' @param data data frame to use for \code{finalize}
#' @param ... not used
#'
#' @return updated workflow set with parameter grid added to the workflow

.finalize_workflow_set <- function(workflow_id, workflow_sets, data, ...) {
  param_set <- workflow_sets %>%
    workflowsets::extract_parameter_set_dials(id = workflow_id)

  if (nrow(param_set) > 0) {
    # Finalize the parameter set
    finalized_param_set <- param_set %>%
      dials::finalize(data)

    workflow_sets_with_finalized_params <- workflow_sets %>%
      workflowsets::option_add(param_info = finalized_param_set, id = workflow_id) %>%
      dplyr::filter(wflow_id == workflow_id)

    return(workflow_sets_with_finalized_params)
  } else {
    tibble::tibble()  # Return an empty tibble if no parameters
  }
}
#' Finalize the workflowset
#'
#' @param x workflow set
#' @param data data frame to use for finalization
#' @param ... additional arguments passed to \code{.finalize_workflow_set}
#'
#' @return updated workflow set with parameter grid added to each workflow

finalize_workflow_set <- function(x, data, ...){
  purrr::map(
    purrr::set_names(x$wflow_id),
    \(z) {
      .finalize_workflow_set(workflow_id = z, workflow_sets = x, data = data, ...)
    }
      ) %>%
    purrr::list_rbind()
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions