### Installing workflowsets from CRAN (R) Source: https://github.com/tidymodels/workflowsets/blob/main/README.md This snippet demonstrates how to install the stable, released version of the `workflowsets` package directly from CRAN. This is the standard method for obtaining the package for general use. ```R install.packages("workflowsets") ``` -------------------------------- ### Installing workflowsets Development Version from GitHub (R) Source: https://github.com/tidymodels/workflowsets/blob/main/README.md This snippet shows how to install the development version of the `workflowsets` package from GitHub using the `pak` package. This is useful for accessing the latest features or bug fixes before they are released on CRAN. It first installs `pak` if not already present, then uses `pak::pak` to install the GitHub version. ```R install.packages("pak") pak::pak("tidymodels/workflowsets") ``` -------------------------------- ### Loading tidymodels and Chicago Data (R) Source: https://github.com/tidymodels/workflowsets/blob/main/README.md This snippet loads the `tidymodels` meta-package, which provides access to core tidymodels packages like `recipes` and `parsnip`. It then loads the `Chicago` dataset, which will be used for subsequent modeling examples. ```R library(tidymodels) data(Chicago) ``` -------------------------------- ### Validating Input for check_wf_set (Data Frame) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/checks.md This example further illustrates the input validation of `check_wf_set`. It highlights that even a `data.frame` object, which is not a `workflow_set`, will trigger an error, reinforcing the requirement for a specific `workflow_set` type to ensure correct operation. ```R check_wf_set(data.frame()) ``` -------------------------------- ### Multiple Mismatched Specs for `tune_cluster` in `workflow_map` (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/workflow-map.md This final example shows an error when `workflow_map()` is configured for `tune_cluster()`, but multiple workflows (`reg_dt` and `reg_nn`) lack the required cluster specification. It reinforces the need for consistent model specification types across workflows when using a specific tuning function. ```R workflow_map(wf_set_3, resamples = folds, fn = "tune_cluster") ``` -------------------------------- ### Retrieving Comments with Non-Existent ID in R Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/comments.md This example illustrates an error when `comment_get()` is called with an `id` (`letters[1]`) that does not correspond to an existing `wflow_id` in the `comments_1` object. ```R comment_get(comments_1, id = letters[1]) ``` -------------------------------- ### Calling collect_extracts without .extracts column (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/collect-extracts.md This R snippet demonstrates the invocation of `collect_extracts` on a `workflow_set` object (`wflow_set_trained`) that is missing the `.extracts` column. This action is designed to show the specific error message generated when this prerequisite column is absent, guiding users to ensure `tune::control_grid()` is configured with a non-`NULL` `extract` argument. ```R collect_extracts(wflow_set_trained) ``` -------------------------------- ### Handling Numeric `fn` Argument in `workflow_map` (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/workflow-map.md This example shows an error when a numeric value (1L) is provided for the `fn` argument in `workflow_map()`. The function expects a character vector specifying the tuning or fitting method, not a numeric type. ```R workflow_map(two_class_set, fn = 1L, seed = 1, resamples = folds, grid = 2) ``` -------------------------------- ### Handling Missing Metric in pick_metric (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/autoplot.md This snippet illustrates an error encountered when using `pick_metric` with a metric that is not present in the results. The function attempts to select 'roc_auc', but the error message indicates that this metric was not found in the `two_class_res` object. ```R pick_metric(two_class_res, "roc_auc", "accuracy") ``` -------------------------------- ### Resetting Comments with Non-Existent ID in R Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/comments.md This example shows `comment_reset()` failing when attempting to reset comments for an `id` ('none_carts') that does not exist within the `wflow_id` of the `comments_1` object. ```R comment_reset(comments_1, "none_carts") ``` -------------------------------- ### Adding Comments with Vector ID in R Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/comments.md This example shows `comment_add()` failing when the `id` argument is provided as a character vector (`letters`) instead of a single string, as required by the function. ```R comment_add(two_class_set, letters, "foot") ``` -------------------------------- ### Mismatched Spec Type for `tune_grid` in `workflow_map` (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/workflow-map.md This example demonstrates an error when `workflow_map()` attempts to use `tune_grid()` (the default `fn`) with a workflow (`reg_km`) that has a cluster specification instead of a standard model specification. The error message suggests using `fn = 'tune_cluster'` for cluster specifications. ```R workflow_map(wf_set_1, resamples = folds) ``` -------------------------------- ### Printing Specific Workflowset Comment by ID in R Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/comments.md This example shows how to use `comment_print()` with the `id` argument to display only the comment associated with a specific workflow ID, in this case, 'none_glm'. ```R comment_print(test, id = "none_glm") ``` -------------------------------- ### Handling Invalid fit() Call on workflowsets with fit_best() Hint in R Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/fit.md This snippet shows another informative error when `fit()` is called on a `workflow_set` object in R. Similar to the previous case, `fit()` is not designed for direct application to a `workflow_set`, but this specific error message guides the user towards `fit_best()` when the intention is to fit the best performing workflow from the set. ```R fit(car_set_2) ``` -------------------------------- ### Adding Duplicate Comment with append=FALSE in R Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/comments.md This example demonstrates an error in `comment_add()` when trying to add a comment for an `id` ('none_cart') that already has a comment, and the `append` argument is set to `FALSE`, preventing overwriting. ```R comment_add(comments_1, "none_cart", "Stuff.", append = FALSE) ``` -------------------------------- ### Handling Invalid Type Argument in autoplot (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/autoplot.md This snippet demonstrates an error when calling `autoplot` with an invalid `type` argument. The function expects `type` to be either 'class' or 'wflow_id', but 'banana' is provided, leading to an error indicating the invalid input. ```R autoplot(two_class_res, metric = "roc_auc", type = "banana") ``` -------------------------------- ### Error for Invalid Metric in `fit_best` (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/fit_best.md This snippet illustrates the error generated by `fit_best` when an unrecognized or invalid metric, such as 'boop', is provided for evaluation. The error message explicitly lists the acceptable metrics (e.g., 'rmse', 'rsq'), guiding the user to choose from the valid set. ```R fit_best(chi_features_map, metric = "boop") ``` -------------------------------- ### Attempting Direct Prediction on workflowset Object (car_set_2) in R Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/predict.md Similar to the previous example, this snippet shows another instance of incorrectly applying `predict()` directly to a `workflowset` object (`car_set_2`). The `workflowsets` package requires specific control options (`save_workflow = TRUE` or `save_pred = TRUE`) and subsequent functions like `fit_best()` or `collect_predictions()` to obtain predictions or the best model for prediction. ```R predict(car_set_2) ``` -------------------------------- ### Creating a Workflow Set for Model Combinations in R Source: https://github.com/tidymodels/workflowsets/blob/main/README.md This snippet demonstrates the creation of a `workflow_set` named `chi_models`. It combines three different preprocessing recipes (`base_recipe`, `filter_rec`, `pca_rec`) with three distinct model specifications (`regularized_spec`, `cart_spec`, `knn_spec`) using `cross = TRUE` to generate all possible 9 combinations of preprocessor and model. ```R chi_models <- workflow_set( preproc = list( simple = base_recipe, filter = filter_rec, pca = pca_rec ), models = list( glmnet = regularized_spec, cart = cart_spec, knn = knn_spec ), cross = TRUE ) chi_models ``` -------------------------------- ### Defining a Base Preprocessing Recipe in R Source: https://github.com/tidymodels/workflowsets/blob/main/README.md This snippet first samples the `Chicago` dataset to reduce its size. It then defines `base_recipe`, a `recipes` object, which outlines a series of preprocessing steps for the `ridership` prediction task. These steps include creating date features, setting `date` as an ID variable, creating dummy variables, removing zero-variance predictors, and normalizing all predictors. ```R Chicago <- Chicago |> slice(1:365) base_recipe <- recipe(ridership ~ ., data = Chicago) |> # create date features step_date(date) |> step_holiday(date) |> # remove date from the list of predictors update_role(date, new_role = "id") |> # create dummy variables from factor columns step_dummy(all_nominal()) |> # remove any columns with a single unique value step_zv(all_predictors()) |> step_normalize(all_predictors()) ``` -------------------------------- ### Adding a PCA Preprocessing Step to a Recipe in R Source: https://github.com/tidymodels/workflowsets/blob/main/README.md This snippet defines `pca_rec` by building upon the `base_recipe`. It incorporates a `step_pca` to perform Principal Component Analysis on the `stations` variables, with the number of components (`num_comp`) set as a tunable parameter. An additional normalization step is applied to all predictors after PCA. ```R pca_rec <- base_recipe |> step_pca(all_of(stations), num_comp = tune()) |> step_normalize(all_predictors()) ``` -------------------------------- ### Displaying `workflow_map` Logging Output (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/workflow-map.md This code demonstrates how to display the logging output generated by `workflow_map()` using `cat()`. The output provides insights into the progress of the mapping process, indicating which workflows are being resampled or tuned and if any have no tuning parameters. ```R cat(logging_res, sep = "\n") ``` -------------------------------- ### Creating Workflow Set with Mismatched Lengths and No Crossing (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/workflow_set.md This R code attempts to create a `workflow_set` with `cross = FALSE`, but the number of preprocessors (3) does not match the number of models (2). This configuration is invalid when `cross` is set to `FALSE`, as it requires a one-to-one mapping between preprocessors and models, leading to an error. ```R nrow(workflow_set(list(reg = mpg ~ ., nonlin = mpg ~ wt + 1 / sqrt(disp), two = mpg ~ wt + disp), list(lm = lr_spec, knn = knn_spec), cross = FALSE)) ``` -------------------------------- ### Creating Workflow Set with Engine Not Supporting Case Weights in R Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/workflow_set.md This R code constructs a `workflow_set` with two model specifications (`lm` and `knn`) and attempts to apply `case_weights`. The `tidymodels` framework issues a warning because the `kknn` engine, used by `knn_spec`, does not inherently support case weights, causing the `case_weights` argument to be ignored for that specific model. ```R car_set_3 <- workflow_set(list(reg = mpg ~ ., nonlin = mpg ~ wt + 1 / sqrt(disp)), list(lm = lr_spec, knn = knn_spec), case_weights = wts) ``` -------------------------------- ### Converting to Workflow Set with Inconsistent Resamples (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/workflow_set.md This R code attempts to convert existing workflow results (`f_1`, `f_2`) into a `workflow_set` using `as_workflow_set`. The error indicates that the input workflow results were generated using different resampling schemes, which is not allowed when combining them into a single `workflow_set` object. ```R as_workflow_set(wt = f_1, disp = f_2) ``` -------------------------------- ### Tuning Workflow Set Models with `workflow_map` in R Source: https://github.com/tidymodels/workflowsets/blob/main/README.md This snippet executes the tuning process for the `chi_models` workflow set using `workflow_map`. It applies `tune_grid` to each workflow, performing a grid search over 10 candidate parameter combinations for each model. The tuning is performed against the `splits` resampling object, and Mean Absolute Error (`mae`) is used as the evaluation metric. ```R set.seed(123) chi_models <- chi_models |> # The first argument is a function name from the {{tune}} package # such as `tune_grid()`, `fit_resamples()`, etc. workflow_map("tune_grid", resamples = splits, grid = 10, metrics = metric_set(mae), verbose = TRUE ) ``` -------------------------------- ### Constructing Workflow Set with Missing 'info' Column (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/workflow_set.md This R code attempts to create a new `workflow_set` object using `new_workflow_set` after removing the `info` column from an existing `car_set_1` object. The error message indicates that the `wflow_id`, `info`, `option`, and `result` columns are mandatory for a valid `workflow_set` object. ```R new_workflow_set(dplyr::select(car_set_1, -info)) ``` -------------------------------- ### Extracting Recipe from Untrained Workflowset (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/extract.md This snippet attempts to extract the recipe from a workflow set using `extract_recipe`. The accompanying error, though referencing `extract_mold` in the provided text, implies that the recipe cannot be extracted if the workflow has not been properly processed or fitted. ```R extract_recipe(car_set_1, id = "reg_lm") ``` -------------------------------- ### Defining Tunable Model Specifications in R Source: https://github.com/tidymodels/workflowsets/blob/main/README.md This snippet defines three different model specifications using `parsnip`: a regularized linear regression (`glmnet`), a decision tree (`rpart`), and a K-nearest neighbors model (`kknn`). Each model includes tunable parameters (`tune()`) for optimization, such as `penalty` and `mixture` for `glmnet`, `cost_complexity` and `min_n` for `rpart`, and `neighbors` and `weight_func` for `kknn`. ```R regularized_spec <- linear_reg(penalty = tune(), mixture = tune()) |> set_engine("glmnet") cart_spec <- decision_tree(cost_complexity = tune(), min_n = tune()) |> set_engine("rpart") |> set_mode("regression") knn_spec <- nearest_neighbor(neighbors = tune(), weight_func = tune()) |> set_engine("kknn") |> set_mode("regression") ``` -------------------------------- ### Constructing Workflow Set with Invalid 'info' Column Type (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/workflow_set.md This R code attempts to create a new `workflow_set` object by mutating the `info` column of `car_set_1` to a character string. The error highlights that the `info` column must be a list, enforcing the correct data structure for `workflow_set` components. ```R new_workflow_set(dplyr::mutate(car_set_1, info = "a")) ``` -------------------------------- ### Plotting Best Workflow Results with autoplot (R) Source: https://github.com/tidymodels/workflowsets/blob/main/README.md This snippet utilizes `autoplot()` with the `select_best = TRUE` argument to display only the best results from each workflow in the `chi_models` object, focusing on optimal performance per workflow rather than all configurations. ```R autoplot(chi_models, select_best = TRUE) ``` -------------------------------- ### Extracting Mold from Untrained Workflowset (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/extract.md This snippet demonstrates an attempt to extract the data mold (preprocessed data structure) from an untrained workflow set using `extract_mold`. The error indicates that the mold cannot be extracted until the workflow has been fitted. ```R extract_mold(car_set_1, id = "reg_lm") ``` -------------------------------- ### Plotting Workflow Rankings with autoplot (R) Source: https://github.com/tidymodels/workflowsets/blob/main/README.md This snippet uses the `autoplot()` method to visualize the overall rankings of different workflows within the `chi_models` object, providing a general overview of model performance across all configurations. ```R autoplot(chi_models) ``` -------------------------------- ### Extracting Engine Fit from Untrained Workflowset (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/extract.md This snippet attempts to extract the engine fit from a workflow set using `extract_fit_engine`. It demonstrates that an error occurs when trying to extract a fit from a workflow that has not yet been trained, indicating the need to call `fit()` first. ```R extract_fit_engine(car_set_1, id = "reg_lm") ``` -------------------------------- ### Constructing Workflow Set with Invalid 'option' Column Type (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/workflow_set.md This R code attempts to create a new `workflow_set` object by mutating the `option` column of `car_set_1` to a character string. The error specifies that the `option` column must be a list, which is used to store options for each workflow within the set. ```R new_workflow_set(dplyr::mutate(car_set_1, option = "a")) ``` -------------------------------- ### Accessing Workflow Set Error Notes (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/workflow_set.md This R code snippet accesses the first error note from a `class_note` object, likely populated from a failed `workflow_map` operation. It demonstrates how to programmatically retrieve detailed error messages from `tidymodels` results, specifically showing the "Can't select columns that don't exist" error. ```R class_note$note[1] ``` -------------------------------- ### Mapping Workflows with Missing Case Weights (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/workflow_set.md This R code attempts to map a workflow set to `fit_resamples` while specifying a `case_weights` column (`boop`) that is not present in the `cars` dataset used for resampling. This results in an error indicating the column does not exist, demonstrating how `workflow_map` handles missing weight columns during resampling. ```R car_set_4 <- workflow_map(workflow_set(list(reg = mpg ~ ., nonlin = mpg ~ wt + 1 / sqrt(disp)), list(lm = lr_spec), case_weights = boop), "fit_resamples", resamples = vfold_cv(cars, v = 5)) ``` -------------------------------- ### Creating Time-Series Resampling Splits in R Source: https://github.com/tidymodels/workflowsets/blob/main/README.md This snippet defines `splits`, a resampling object, using `sliding_period` for time-series cross-validation on the `Chicago` dataset. It configures the splits to use a 300-day lookback window for training, a 7-day assessment period, and a 7-day step to ensure non-overlapping assessment sets, suitable for time-dependent data. ```R splits <- sliding_period( Chicago, date, "day", lookback = 300, # Each resample has 300 days for modeling assess_stop = 7, # One week for performance assessment step = 7 # Ensure non-overlapping weeks for assessment ) splits ``` -------------------------------- ### Ranking Workflow Results by MAE (R) Source: https://github.com/tidymodels/workflowsets/blob/main/README.md This snippet ranks the best results from each workflow in `chi_models` based on the 'mae' (mean absolute error) metric. It then selects and displays specific columns: rank, mean metric, model type, workflow ID, and configuration, providing a tabular summary of top performers. ```R rank_results(chi_models, rank_metric = "mae", select_best = TRUE) |> select(rank, mean, model, wflow_id, .config) ``` -------------------------------- ### Error for Missing `save_workflow` Option in `fit_best` (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/fit_best.md This snippet demonstrates the error thrown by the `fit_best` function when the `save_workflow = TRUE` control option was not enabled during the initial tuning process. This option is a prerequisite for `fit_best` to access and utilize the necessary workflow information, ensuring proper model fitting. ```R fit_best(chi_features_res) ``` -------------------------------- ### Handling Invalid fit() Call on workflowsets in R Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/fit.md This snippet demonstrates an informative error when attempting to call `fit()` directly on a `workflow_set` object in R. The error message clearly states that `fit()` is not well-defined for workflow sets and suggests using `workflow_map()` for fitting multiple workflows within a set. ```R fit(car_set_1) ``` -------------------------------- ### Error for Unexpected Arguments in `fit_best` (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/fit_best.md This snippet shows the error produced by `fit_best` when additional, unexpected arguments like `boop = "bop"` are passed to the function. The error indicates that the `...` (dots) argument must be empty, enforcing strict adherence to the function's defined parameters and preventing misconfigurations. ```R fit_best(chi_features_map, boop = "bop") ``` -------------------------------- ### Validating Input for check_wf_set (String) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/checks.md This snippet demonstrates the input validation of the `check_wf_set` function. It shows that passing a simple string like "no" instead of a `workflow_set` object results in an error, indicating the function's strict type checking for its primary argument. ```R check_wf_set("no") ``` -------------------------------- ### Calling collect_notes in R Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/collect-notes.md This snippet demonstrates calling the `collect_notes()` function with a `wflow_set` object. It is shown in the context of an error where the function indicates that some workflows within the set had no results, leading to a failure. The error message 'There were 2 workflows that had no results.' is a direct output of this function call under specific conditions. ```R collect_notes(wflow_set) ``` -------------------------------- ### Adding a Correlation Filter Step to a Recipe in R Source: https://github.com/tidymodels/workflowsets/blob/main/README.md This snippet extends the `base_recipe` by adding a `step_corr` step. This step is designed to filter out highly correlated predictors (specifically `stations`) based on a tunable `threshold`, which will be optimized during the tuning process. ```R filter_rec <- base_recipe |> step_corr(all_of(stations), threshold = tune()) ``` -------------------------------- ### Multiple Mismatched Specs for `tune_grid` in `workflow_map` (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/workflow-map.md Similar to the previous snippet, this shows an error when multiple workflows (`reg_km` and `reg_hc`) with cluster specifications are passed to `workflow_map()` while `tune_grid()` is implicitly selected. The error advises using `fn = 'tune_cluster'` for these types of specifications. ```R workflow_map(wf_set_2, resamples = folds) ``` -------------------------------- ### Extracting Non-Existent Parameter from Workflow Set (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/extract.md This snippet demonstrates using `hardhat::extract_parameter_dials` to retrieve a parameter from a workflow set. The error occurs because the specified `parameter` ID ('non there') does not exist within the workflow, highlighting the need for a valid parameter identifier. ```R hardhat::extract_parameter_dials(wf_set, id = "reg_lm", parameter = "non there") ``` -------------------------------- ### Constructing Workflow Set with Invalid 'result' Column Type (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/workflow_set.md This R code attempts to create a new `workflow_set` object by mutating the `result` column of `car_set_1` to a character string. The error indicates that the `result` column must be a list, ensuring proper storage of model fitting results within the `workflow_set`. ```R new_workflow_set(dplyr::mutate(car_set_1, result = "a")) ``` -------------------------------- ### Handling Function Object as `fn` Argument in `workflow_map` (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/workflow-map.md This snippet illustrates an error when a direct function object (e.g., `tune::tune_grid`) is passed to the `fn` argument of `workflow_map()`. The `fn` parameter requires the function name as a character string, not the function itself. ```R workflow_map(two_class_set, fn = tune::tune_grid, seed = 1, resamples = folds, grid = 2) ``` -------------------------------- ### Handling Invalid `fn` Argument in `workflow_map` (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/workflow-map.md This snippet demonstrates an error when an invalid function name 'foo' is passed to the `fn` argument of `workflow_map()`. The error message clearly lists the acceptable values for the `fn` parameter, which are specific tuning or fitting functions from the `tidymodels` ecosystem. ```R workflow_map(two_class_set, "foo", seed = 1, resamples = folds, grid = 2) ``` -------------------------------- ### Validating Input for rank_results (String) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/checks.md This snippet showcases the input validation for the `rank_results` function. It confirms that providing a string instead of a `workflow_set` object leads to an error, ensuring that the function operates only on valid `workflow_set` inputs for ranking results. ```R rank_results("beeEeEEp!") ``` -------------------------------- ### Handling Invalid `grid` Argument in `workflow_map` (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/workflow-map.md This snippet shows how `workflow_map()` handles an invalid `grid` argument, specifically when a character string ('a') is provided instead of a positive integer or data frame. The `verbose = TRUE` option ensures that detailed messages, including failures and their reasons, are printed during execution. ```R res_loud <- workflow_map(car_set_3, resamples = folds, seed = 2, verbose = TRUE, grid = "a") ``` -------------------------------- ### Extracting Parsnip Fit from Untrained Workflowset (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/extract.md This snippet attempts to extract the parsnip model fit from a workflow set using `extract_fit_parsnip`. Similar to `extract_fit_engine`, it shows that an error is raised if the workflow has not been trained, requiring a prior call to `fit()`. ```R extract_fit_parsnip(car_set_1, id = "reg_lm") ``` -------------------------------- ### Printing All Workflowset Comments in R Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/comments.md This snippet demonstrates the use of `comment_print()` to display all comments associated with the `test` workflowset object. It outputs the comments formatted with their respective IDs. ```R comment_print(test) ``` -------------------------------- ### Mismatched Spec Type for `tune_cluster` in `workflow_map` (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/workflow-map.md This snippet illustrates an error when `workflow_map()` is explicitly told to use `tune_cluster()`, but one of the workflows (`reg_dt`) does not have a cluster specification. This highlights the importance of matching the workflow's model type with the chosen tuning function. ```R workflow_map(wf_set_1, resamples = folds, fn = "tune_cluster") ``` -------------------------------- ### Calling Deprecated pull_workflow_set_result in R Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/pull.md This snippet demonstrates the use of the `pull_workflow_set_result()` function, which has been deprecated and is now defunct in the `workflowsets` package. Users should migrate to `extract_workflow_set_result()` for retrieving workflow set results. The error message indicates its removal from version 0.1.0 onwards. ```R pull_workflow_set_result(car_set_1, "reg_lm") ``` -------------------------------- ### Retrieving Error Message from Failed Workflow in R Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/workflow_set.md This R code retrieves the first error message from the `class_note` object, which likely stores diagnostic information from a failed `tidymodels` operation. It is used to inspect the specific reason for the failure, in this case, confirming that the `case_weights` column was not properly classed. ```R class_note$note[1] ``` -------------------------------- ### Mapping Workflows with Invalid Case Weights in R Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/workflow_set.md This R code attempts to map a workflow set using `workflow_map` and `workflow_set` functions from the `tidymodels` package. It specifies `non_wts` as `case_weights`, which is not a properly classed case weights column, leading to errors during resampling. The purpose is to demonstrate the requirement for `case_weights` to be a column created by `hardhat::frequency_weights()` or `hardhat::importance_weights()`. ```R car_set_2 <- workflow_map(workflow_set(list(reg = mpg ~ ., nonlin = mpg ~ wt + 1 / sqrt(disp)), list(lm = lr_spec), case_weights = non_wts), "fit_resamples", resamples = vfold_cv(cars, v = 5)) ``` -------------------------------- ### Calling Deprecated pull_workflow in R Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/pull.md This snippet illustrates the usage of the `pull_workflow()` function, which is deprecated and defunct in the `workflowsets` package. The recommended replacement for extracting individual workflows is `extract_workflow()`. The error message confirms its removal from version 0.1.0. ```R pull_workflow(car_set_1, "reg_lm") ``` -------------------------------- ### Constructing Workflow Set with Invalid 'wflow_id' Column Type (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/workflow_set.md This R code attempts to create a new `workflow_set` object by mutating the `wflow_id` column of `car_set_1` to a numeric value. The error clarifies that the `wflow_id` column must be of character type, serving as unique identifiers for each workflow. ```R new_workflow_set(dplyr::mutate(car_set_1, wflow_id = 1)) ``` -------------------------------- ### Constructing Workflow Set with Non-Unique 'wflow_id' (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/workflow_set.md This R code attempts to create a new `workflow_set` object by mutating the `wflow_id` column of `car_set_1` to a non-unique character string ("a"). The error states that `wflow_id` values must be unique and non-missing, enforcing the integrity of workflow identifiers within the set. ```R new_workflow_set(dplyr::mutate(car_set_1, wflow_id = "a")) ``` -------------------------------- ### Attempting Direct Prediction on workflowset Object (car_set_1) in R Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/predict.md This snippet demonstrates an incorrect attempt to use `predict()` directly on a `workflowset` object (`car_set_1`). The `workflowsets` package does not support direct prediction on the set itself. Instead, users must either extract the optimal fitted workflow using `fit_best()` (after setting `save_workflow = TRUE`) and predict on that, or collect all predictions using `collect_predictions()` (after setting `save_pred = TRUE`). ```R predict(car_set_1) ``` -------------------------------- ### Adding Comments with Non-Existent ID in R Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/comments.md This snippet demonstrates an attempt to add a comment using `comment_add()` with an `id` ('toe') that does not exist within the `wflow_id` of the `two_class_set` object, resulting in an error. ```R comment_add(two_class_set, "toe", "foot") ``` -------------------------------- ### Extracting Workflow with Invalid ID (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/extract.md This snippet attempts to extract a specific workflow from a workflow set using `extract_workflow` with an `id` that does not correspond to an existing workflow. The error message clarifies that the `id` must match a single row in the workflow set. ```R extract_workflow(car_set_1, "Coronabeth Tridentarius") ``` -------------------------------- ### Retrieving Comments with Vector ID in R Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/comments.md This snippet shows `comment_get()` failing because the `id` argument is provided as a character vector (`letters`) instead of a single character value, as required for retrieving comments. ```R comment_get(comments_1, id = letters) ``` -------------------------------- ### Handling `leave_var_out_formulas` with single predictor formula (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/leave-var-out-formulas.md This snippet illustrates the error produced when `leave_var_out_formulas` is invoked with a formula containing only one predictor (`y ~ a`). The function's design mandates a minimum of two predictors, leading to an error message about the lack of sufficient predictors. ```R leave_var_out_formulas(y ~ a, data = form_data) ``` -------------------------------- ### Adding Comments with Integer Vector ID in R Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/comments.md Here, `comment_add()` generates an error because the `id` argument is an integer vector (`1:2`), violating the requirement for `id` to be a single string. ```R comment_add(two_class_set, 1:2, "foot") ``` -------------------------------- ### Handling `leave_var_out_formulas` with intercept-only formula (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/leave-var-out-formulas.md This snippet demonstrates the error encountered when `leave_var_out_formulas` is called with an intercept-only formula (`y ~ 1`). The function requires at least two predictors to perform its operation, resulting in an error indicating insufficient predictors. ```R leave_var_out_formulas(y ~ 1, data = form_data) ``` -------------------------------- ### Extracting Workflow Set Result with Invalid ID (R) Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/extract.md This snippet shows an attempt to extract a specific workflow set result using `extract_workflow_set_result` with an invalid or non-existent `id`. The error indicates that the provided `id` must uniquely identify a row within the workflow set. ```R extract_workflow_set_result(car_set_1, "Gideon Nav") ``` -------------------------------- ### Adding Comments with Non-String Comment Value in R Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/comments.md This snippet illustrates an error when attempting to add a comment where the comment value (`1:2`) is not a character string, which is a requirement for the `comment_add()` function. ```R comment_add(two_class_set, "none_cart", 1:2) ``` -------------------------------- ### Excluding Specific Workflows from a Workflow Set in R Source: https://github.com/tidymodels/workflowsets/blob/main/README.md This snippet modifies the `chi_models` workflow set by removing specific combinations that are deemed illogical or unnecessary. It uses `anti_join` to exclude workflows where PCA or correlation filtering is applied with the `glmnet` model, streamlining the set for more meaningful evaluations. ```R chi_models <- chi_models |> anti_join(tibble(wflow_id = c("pca_glmnet", "filter_glmnet")), by = "wflow_id" ) ``` -------------------------------- ### Resetting Comments with Vector ID in R Source: https://github.com/tidymodels/workflowsets/blob/main/tests/testthat/_snaps/comments.md This snippet demonstrates `comment_reset()` generating an error because the `id` argument is a character vector (`letters`) instead of a single character value, which is necessary to reset comments for a specific ID. ```R comment_reset(comments_1, letters) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.