### Installing workflows R Package Development Version from GitHub Source: https://github.com/tidymodels/workflows/blob/main/README.md This snippet shows how to install the development version of the 'workflows' package directly from its GitHub repository. It uses the 'pak' package for installation, which might need to be installed first. ```R pak::pak("tidymodels/workflows") ``` -------------------------------- ### Installing workflows R Package from CRAN Source: https://github.com/tidymodels/workflows/blob/main/README.md This snippet demonstrates how to install the 'workflows' package from CRAN, the comprehensive R Archive Network. This is the standard and recommended way to get the stable version of the package. ```R install.packages("workflows") ``` -------------------------------- ### Fitting tidymodels Workflow with Sparse Matrices and Recipe Interface (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/sparsevctrs.md This example shows the successful application of `fit()` to sparse matrix data when the recipe interface is employed. The `sparsevctrs` package materializes the sparse vector, indicating proper handling and conversion of the sparse input. This confirms that the recipe interface is compatible with sparse matrices. ```R wf_fit <- fit(wf_spec, hotel_data) ``` -------------------------------- ### Initializing Workflow with Model Specification Lacking Implementation (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/fit-action-model.md This snippet demonstrates an error when initializing a workflow directly with a model specification (`mod`) for which `parsnip` cannot locate an implementation. Similar to `add_model()`, it advises installing and loading the relevant extension package (e.g., `baguette`) that provides support for the model. ```R workflow(spec = mod) ``` -------------------------------- ### Adding Model Specification with Missing Implementation in tidymodels (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/fit-action-model.md This snippet shows an error when `parsnip` cannot find an implementation for a specified model, such as `bag_tree` regression. It indicates that an extension package (e.g., `baguette`) is required and must be installed and loaded to support the model specification. ```R add_model(workflow, mod) ``` -------------------------------- ### Validating Blueprint Type in add_formula() (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pre-action-formula.md This example illustrates that the `blueprint` argument in `add_formula()` must be of type `hardhat `. Providing an incompatible blueprint will result in an error, enforcing correct blueprint usage for formula processing. ```R add_formula(workflow, mpg ~ cyl, blueprint = blueprint) ``` -------------------------------- ### Preventing Formula Addition with Existing Recipe in add_formula() (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pre-action-formula.md This example illustrates a constraint where `add_formula()` cannot be used if a recipe has already been defined in the workflow. Attempting to add a formula in such a scenario will result in an error, enforcing a clear workflow structure. ```R add_formula(workflow, mpg ~ cyl) ``` -------------------------------- ### Preventing Multiple Formulas in add_formula() (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pre-action-formula.md This example demonstrates that a workflow can only have one formula action defined. Attempting to add a second formula using `add_formula()` will result in an error, ensuring a single, clear model specification. ```R add_formula(workflow, mpg ~ cyl) ``` -------------------------------- ### Predicting with Unsupported Type in tidymodels Workflow (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/predict.md This example illustrates an error encountered when attempting to use an `unsupported` `prediction type` ('boop') with the `predict()` function on a `tidymodels` workflow that includes a `postprocessor` in R. The error message clarifies that the specified prediction type is not valid for workflows configured with postprocessing steps. ```R predict(wflow_fit, d[1:5, ], type = "boop") ``` -------------------------------- ### Case Weights: Column Must Inherit Base Class (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pre-action-case-weights.md This snippet demonstrates that the column designated as case weights must inherit from a specific base case weights class, as determined by `hardhat::is_case_weights()`. Examples include columns created by `hardhat::frequency_weights()` or `hardhat::importance_weights()`. ```R fit(wf, df) ``` -------------------------------- ### Handling Offsets with add_formula() in tidymodels (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pre-action-formula.md This snippet shows that `add_formula()` does not support specifying offsets directly within its formula argument. The error message guides users to define offsets through the model formula in `add_model(formula = )` instead, ensuring proper model specification. ```R fit(workflow, data = df) ``` -------------------------------- ### Printing Workflow with All Components (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/printing.md Demonstrates the comprehensive print output of a `tidymodels` workflow that includes a `formula` preprocessor, `case weights`, and a `model` specification. All sections are displayed in the output. ```R workflow ``` -------------------------------- ### Fitting and Printing a Workflow (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/printing.md Demonstrates fitting a `tidymodels` workflow to data (e.g., `mtcars`). The output shows the workflow's 'trained' status, the preprocessor (formula), the model, and the resulting model call and coefficients. ```R fit(workflow, mtcars) ``` -------------------------------- ### Adding and Printing Workflow with Model and Engine Arguments (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/printing.md Shows how a `tidymodels` workflow displays a model with specific main and engine-specific arguments (e.g., `penalty` and `dfmax`). The output details these arguments under the model specification. ```R add_model(workflow(), model) ``` -------------------------------- ### Adding and Printing Workflow with Recipe (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/printing.md Illustrates how to add a `recipe` preprocessor to a `tidymodels` workflow. This snippet shows the workflow's state when a recipe is attached, indicating 'Preprocessor: Recipe'. ```R add_recipe(workflow(), rec) ``` -------------------------------- ### Adding and Printing Workflow with Many Recipe Steps (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/printing.md Illustrates how a `tidymodels` workflow summarizes a `recipe` with more than 10 steps. Instead of listing all steps, it shows the count and truncates the display with '...' and 'and X more steps'. ```R add_recipe(workflow(), rec) ``` -------------------------------- ### Printing Empty Workflow (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/printing.md Demonstrates how to initialize and print an empty `tidymodels` workflow object. This shows the default state of a workflow before any preprocessor or model components are added. ```R workflow() ``` -------------------------------- ### Adding and Printing Workflow with Formula (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/printing.md Shows how to add a `formula` preprocessor to a `tidymodels` workflow. The output confirms the formula `y ~ x` is recognized as the preprocessor. ```R add_formula(workflow(), y ~ x) ``` -------------------------------- ### Adding and Printing Workflow with Model (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/printing.md Illustrates how to attach a `model` specification (e.g., `linear_reg()`) to a `tidymodels` workflow. The output displays the model type and its computational engine. ```R add_model(workflow(), model) ``` -------------------------------- ### Printing Workflow with Case Weights (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/printing.md Shows how a `tidymodels` workflow object is printed when only `case weights` have been added. The output includes a dedicated section for 'Case Weights' showing the variable used. ```R workflow ``` -------------------------------- ### Extracting Preprocessor from Empty Workflow (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/extract.md This snippet demonstrates calling `extract_preprocessor()` on an empty `workflow()` object. It fails because the workflow has no preprocessor defined, indicating that a recipe or formula must be added to the workflow before extraction. ```R extract_preprocessor(workflow()) ``` -------------------------------- ### Traditional Recipe Preprocessing and Model Fitting in R Source: https://github.com/tidymodels/workflows/blob/main/README.md This R snippet demonstrates the traditional approach to preparing a recipe and fitting a model separately. It first preps the 'spline_cars' recipe with 'mtcars' data, then uses the 'juice'd data to fit the 'bayes_lm' model. ```R spline_cars_prepped <- prep(spline_cars, mtcars) bayes_lm_fit <- fit(bayes_lm, mpg ~ ., data = juice(spline_cars_prepped)) ``` -------------------------------- ### Extracting Recipe from Untrained Workflow (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/extract.md This snippet attempts to extract a recipe from an untrained workflow. The observed error message refers to `extract_mold()`, implying that the recipe, if it's a prepped recipe, also requires the workflow to be fitted. ```R extract_recipe(workflow) ``` -------------------------------- ### Printing a Workflow with Postprocessor in R Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/printing.md This snippet demonstrates how to print a `workflow` object in R that has a postprocessor attached. The output shows the structured representation of the workflow, detailing its preprocessor, model, and postprocessor components, along with specific information about the postprocessor. ```R workflow ``` -------------------------------- ### Fitting a Workflow Object in R Source: https://github.com/tidymodels/workflows/blob/main/README.md This R snippet demonstrates how to fit a complete workflow object. The 'fit()' function, when applied to a workflow, automatically handles both the recipe preprocessing and the model fitting steps using the provided data. ```R car_wflow_fit <- fit(car_wflow, data = mtcars) ``` -------------------------------- ### Fitting tidymodels Workflow with Sparse Matrices and XY Interface (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/sparsevctrs.md This snippet demonstrates that `fit()` successfully handles sparse matrix data when the `xy` interface is utilized. The `sparsevctrs` package materializes the sparse vector, confirming that this interface correctly processes sparse inputs. This provides an alternative successful method for fitting models with sparse matrices. ```R wf_fit <- fit(wf_spec, hotel_data) ``` -------------------------------- ### Tidying Workflow Recipe Without Preprocessor (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/broom.md Attempts to tidy the recipe component of a `tidymodels` workflow. This error indicates that the workflow object `x` does not contain a recipe preprocessor, which is a prerequisite for extracting recipe details. ```R tidy(x, what = "recipe") ``` -------------------------------- ### Error Handling: Extracting Prepped Recipe from Untrained Workflow (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pull.md Illustrates an error when attempting to extract a prepped recipe from an untrained workflow object using `pull_workflow_prepped_recipe()`. The error suggests that the `fit()` method needs to be called first to train the workflow and prepare the recipe. ```R pull_workflow_prepped_recipe(workflow) ``` -------------------------------- ### Extracting Recipe from Workflow Without Recipe (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/extract.md Calling `extract_recipe()` on an empty `workflow()` object results in an error because the workflow has no recipe preprocessor defined. A recipe must be added to the workflow before it can be extracted. ```R extract_recipe(workflow()) ``` -------------------------------- ### Extracting Mold from Untrained Workflow (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/extract.md Attempting to extract the mold from an untrained `workflow()` object using `extract_mold()` will fail. The mold, which contains preprocessed data, is only available after the workflow has been `fit()`. ```R extract_mold(workflow()) ``` -------------------------------- ### Fitting Workflow Without Preprocessor (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/fit.md This snippet illustrates an error when attempting to fit a workflow that lacks a necessary preprocessor (formula, recipe, or variables). The condition `Error in `.fit_pre()`: ! The workflow must have a formula, recipe, or variables preprocessor. i Provide one with `add_formula()`, `add_recipe()`, or `add_variables()`.` suggests adding one using `add_formula()`, `add_recipe()`, or `add_variables()`. ```R fit(workflow, mtcars) ``` -------------------------------- ### Defining a Recipe for Nonlinear Transformation in R Source: https://github.com/tidymodels/workflows/blob/main/README.md This R snippet defines a data recipe using the 'recipes' package to preprocess the 'mtcars' dataset. It specifies a nonlinear relationship for engine displacement ('disp') using a natural spline with 10 degrees of freedom, preparing the data for modeling. ```R library(recipes) library(parsnip) library(workflows) spline_cars <- recipe(mpg ~ ., data = mtcars) |> step_ns(disp, deg_free = 10) ``` -------------------------------- ### Adding and Printing Workflow with Variables (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/printing.md Demonstrates adding `variables` as a preprocessor to a `tidymodels` workflow, specifying outcomes and predictors. The workflow output clearly lists 'Outcomes: y' and 'Predictors: c(x1, x2)'. ```R add_variables(workflow(), y, c(x1, x2)) ``` -------------------------------- ### Creating a Workflow Object in R Source: https://github.com/tidymodels/workflows/blob/main/README.md This R snippet illustrates how to combine a pre-defined recipe ('spline_cars') and a model ('bayes_lm') into a single 'workflow' object. This streamlines the modeling process by bundling preprocessing and modeling steps. ```R car_wflow <- workflow() |> add_recipe(spline_cars) |> add_model(bayes_lm) ``` -------------------------------- ### Error Handling: Extracting Preprocessor from Empty Workflow (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pull.md Demonstrates an error when attempting to extract a preprocessor from an empty or unconfigured workflow object using `pull_workflow_preprocessor()`. The error indicates that no preprocessor is attached to the workflow, requiring it to be added before extraction. ```R pull_workflow_preprocessor(workflow()) ``` -------------------------------- ### Error Handling: Extracting Mold from Untrained Workflow (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pull.md Demonstrates an error when attempting to extract a mold from an untrained workflow object using `pull_workflow_mold()`. The error suggests that the `fit()` method needs to be called first to train the workflow and generate the mold. ```R pull_workflow_mold(workflow()) ``` -------------------------------- ### Tidying Untrained Workflow Recipe Mold (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/broom.md Attempts to tidy the recipe component of an untrained `tidymodels` workflow. This specific error occurs when trying to extract the 'mold' (processed data structure) from a workflow that has not been fitted, necessitating a call to `fit()`. ```R tidy(x, what = "recipe") ``` -------------------------------- ### Extracting Recipe with Unnamed Argument (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/extract.md This code attempts to extract a recipe, passing `FALSE` as an unnamed argument. The `extract_recipe()` function expects its `...` arguments to be empty or named, leading to an error when an unhandled positional argument is provided. ```R extract_recipe(workflow, FALSE) ``` -------------------------------- ### Tidying Untrained Workflow Model Fit (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/broom.md Attempts to tidy the model fit from an untrained `tidymodels` workflow. This operation fails because the workflow's model component has not been fitted, requiring a prior call to `fit()` to generate the fit object. ```R tidy(x) ``` -------------------------------- ### Error Handling: Extracting Prepped Recipe without Recipe Preprocessor (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pull.md Demonstrates an error when attempting to extract a prepped recipe from a workflow that lacks a recipe preprocessor using `pull_workflow_prepped_recipe()`. The error indicates that a recipe preprocessor must be attached to the workflow for this operation. ```R pull_workflow_prepped_recipe(workflow()) ``` -------------------------------- ### Missing Required Calibration Set for `fit()` (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/fit.md This snippet demonstrates an error when a workflow *requires* a `calibration` set for training, but none is supplied to the `fit()` function. The condition `Error in `fit()`: ! The workflow requires a `calibration` set to train but none was supplied.` explicitly states the requirement. ```R fit(workflow, mtcars) ``` -------------------------------- ### Extracting Preprocessor with Invalid Input (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/extract.md This code attempts to use `extract_preprocessor()` with a numeric input (1) instead of a `workflow` object. The error indicates that the function expects a `workflow` object and does not have a method for numeric types. ```R extract_preprocessor(1) ``` -------------------------------- ### Validating Preprocessor Argument in workflow Constructor (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/workflow.md This snippet illustrates the validation of the `preprocessor` argument in the `workflow()` constructor. It requires `preprocessor` to be a formula, recipe, or workflow variables, but a numeric value `1` was supplied, resulting in an error. ```R workflow(preprocessor = 1) ``` -------------------------------- ### Fitting tidymodels Workflow with Sparse Tibble and Formula Interface (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/sparsevctrs.md This snippet demonstrates that the `fit()` function in `tidymodels` cannot process sparse tibble data when using the formula interface. An error is thrown, advising users to switch to `add_recipe()` or `add_variables()` for sparse data handling. This highlights a limitation of the formula interface with sparse data structures. ```R wf_fit <- fit(wf_spec, hotel_data) ``` -------------------------------- ### Supplying Unnecessary Calibration Set to `fit()` (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/fit.md This snippet shows a warning issued when a `calibration` set is provided to `fit()` even though the workflow does not require one for training. The condition `Warning in `fit()`: The workflow does not require a `calibration` set to train but one was supplied.` indicates a potentially redundant argument. ```R res <- fit(workflow, mtcars, calibration = mtcars) ``` -------------------------------- ### Identifying Unused Imports in `modeltime.resample` (R) Source: https://github.com/tidymodels/workflows/blob/main/revdep/problems.md This R code snippet lists dependency warnings for the `modeltime.resample` package. It notes that several namespaces (`crayon`, `dials`, `glue`, `parsnip`) are declared as imports but are not utilized in the package's R code. This indicates potential dead code or unnecessary dependencies that should be reviewed. ```R Namespaces in Imports field not imported from: ‘crayon’ ‘dials’ ‘glue’ ‘parsnip’ All declared Imports should be used. ``` -------------------------------- ### Fitting tidymodels Workflow with Sparse Matrices and Formula Interface (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/sparsevctrs.md Similar to sparse tibbles, this snippet illustrates that `fit()` fails to process sparse matrix data when the formula interface is used. The error message explicitly directs users to utilize `add_recipe()` or `add_variables()` instead. This reinforces the incompatibility of the formula interface with sparse data types. ```R wf_fit <- fit(wf_spec, hotel_data) ``` -------------------------------- ### Validating Blueprint Type for Recipe in tidymodels/workflows (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pre-action-recipe.md This snippet shows an error when `add_recipe()` is called with an invalid `blueprint` argument. The function specifically requires a `hardhat ` object to correctly process and prepare the data, ensuring compatibility with the `tidymodels` ecosystem. ```R add_recipe(workflow, rec, blueprint = blueprint) ``` -------------------------------- ### Deprecation Warning: `pull_workflow_prepped_recipe()` (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pull.md Shows the deprecation warning for `pull_workflow_prepped_recipe()`. This function is soft-deprecated in `workflows` version 0.2.3, and users are advised to use `extract_recipe()` for future compatibility and improved functionality. ```R x <- pull_workflow_prepped_recipe(workflow) ``` -------------------------------- ### Error Handling: Invalid Input for Prepped Recipe Extraction (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pull.md Illustrates an error when `pull_workflow_prepped_recipe()` is invoked with a non-workflow argument. The function expects a workflow object to extract the prepped recipe, but a numeric value is provided, resulting in a type error. ```R pull_workflow_prepped_recipe(1) ``` -------------------------------- ### Validating Fit Stage in new_workflow Constructor (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/workflow.md This snippet demonstrates the input validation for the `fit` argument in the `new_workflow()` constructor. It shows that `fit` must be a `stage` object, but a numeric value `1` was provided, leading to an error. ```R new_workflow(fit = 1) ``` -------------------------------- ### Preventing Multiple Recipes in tidymodels/workflows (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pre-action-recipe.md This snippet illustrates an error when attempting to add a second recipe to a workflow that already contains one. A workflow is designed to manage a single recipe for data preprocessing, and adding multiple recipes is not supported, leading to an error indicating a duplicate action. ```R add_recipe(workflow, rec) ``` -------------------------------- ### Extracting Recipe with Invalid Input (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/extract.md This code attempts to extract a recipe using `extract_recipe()` on a numeric input. The error indicates that the function expects a `workflow` object and cannot operate on a numeric type. ```R extract_recipe(1) ``` -------------------------------- ### Error Handling: Extracting Fit from Untrained Workflow (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pull.md Illustrates an error when attempting to extract a model fit from an untrained workflow object using `pull_workflow_fit()`. The error suggests that the `fit()` method needs to be called first to train the workflow and obtain a fit. ```R pull_workflow_fit(workflow()) ``` -------------------------------- ### Predicting with Untrained tidymodels Workflow (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/predict.md This snippet demonstrates an attempt to use the `predict()` function on an `untrained` `tidymodels` workflow in R. The operation fails with an error message indicating that the workflow must first be `fit()` before predictions can be generated, emphasizing a crucial prerequisite for model application. ```R predict(workflow(), mtcars) ``` -------------------------------- ### Debugging `modeltime.resample` Vignette Rebuilding (R) Source: https://github.com/tidymodels/workflows/blob/main/revdep/problems.md This R code snippet details a warning encountered during the re-building of vignettes for the `modeltime.resample` package. Specifically, the `panel-data.Rmd` vignette failed due to a `parsnip` error, indicating that a model specification (`spec`) lacked a known mode. This requires setting the mode using `parsnip::set_mode()`. ```R Error(s) in re-building vignettes: --- re-building ‘getting-started.Rmd’ using rmarkdown ── Attaching packages ────────────────────────────────────── tidymodels 1.0.0 ── ✔ broom 1.0.1 ✔ recipes 1.0.1 ✔ dials 1.0.0 ✔ rsample 1.1.0 ✔ dplyr 1.0.10 ✔ tibble 3.1.8 ✔ ggplot2 3.3.6 ✔ tidyr 1.2.1 ✔ infer 1.0.3 ✔ tune 1.0.0 ✔ modeldata 1.0.1 ✔ workflows 1.1.0 ✔ parsnip 1.0.1 ✔ workflowsets 1.0.0 ... Error: processing vignette 'panel-data.Rmd' failed with diagnostics: `spec` must have a known mode. ℹ Set the mode of `spec` by using `parsnip::set_mode()` or by setting the mode directly in the parsnip specification function. --- failed re-building ‘panel-data.Rmd’ SUMMARY: processing the following file failed: ‘panel-data.Rmd’ Error: Vignette re-building failed. Execution halted ``` -------------------------------- ### Validating Pre Stage in new_workflow Constructor (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/workflow.md This snippet highlights the input validation for the `pre` argument in the `new_workflow()` constructor. It mandates that `pre` must be a `stage` object, but a numeric value `1` was passed, causing an error. ```R new_workflow(pre = 1) ``` -------------------------------- ### Validating Post Stage in new_workflow Constructor (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/workflow.md This snippet illustrates the input validation for the `post` argument in the `new_workflow()` constructor. It requires `post` to be a `stage` object, but a numeric value `1` was supplied, resulting in an error. ```R new_workflow(post = 1) ``` -------------------------------- ### Predicting from Untrained Workflow (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/fit.md This snippet illustrates an error when attempting to call `predict()` on a workflow that has not yet been trained (fitted). The condition `Error in `predict()`: ! Can't predict on an untrained workflow. i Do you need to call `fit()`?` suggests calling `fit()` first. ```R predict(workflow_model, mtcars) ``` -------------------------------- ### Identifying Unused Imports in `modeltime.ensemble` (R) Source: https://github.com/tidymodels/workflows/blob/main/revdep/problems.md This R code snippet highlights a dependency warning for the `modeltime.ensemble` package. It indicates that the `parsnip` namespace is declared in the `Imports` field of the package's `DESCRIPTION` file but is not actually used within the package's R code. This suggests a potential cleanup opportunity for package dependencies. ```R Namespace in Imports field not imported from: ‘parsnip’ All declared Imports should be used. ``` -------------------------------- ### Error Handling for Sparse Matrices Without Colnames in tidymodels `fit()` (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/sparsevctrs.md This snippet shows that the `fit()` function requires input matrices to have column names, even when dealing with sparse data. An error is generated if `x` (the input data) lacks column names, indicating a critical prerequisite for model fitting. This emphasizes the importance of well-structured input data. ```R fit(wf_spec, hotel_data) ``` -------------------------------- ### Validating Workflow Argument in add_recipe (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/workflow.md This snippet illustrates the input validation for the `add_recipe()` function. It requires the first argument `x` to be a `workflow` object, but a numeric value `1` was supplied, resulting in an error. ```R add_recipe(1, rec) ``` -------------------------------- ### Debugging `modeltime.ensemble` Test Failures (R) Source: https://github.com/tidymodels/workflows/blob/main/revdep/problems.md This R code snippet shows the backtrace for a test failure in the `modeltime.ensemble` package. Similar to `modeltime`, the issue arises during workflow construction, specifically when adding a `boost_tree` model with the `xgboost` engine or processing a recipe. The error points to an invalid workflow object during validation. ```R Running ‘testthat.R’ Running the tests in ‘tests/testthat.R’ failed. Last 13 lines of output: Backtrace: ▆ 1. ├─... |> fit(data_set) at test-panel-data.R:28:0 2. ├─generics::fit(., data_set) 3. ├─workflows::add_recipe(., recipe_spec |> step_rm(date)) 4. │ └─workflows:::add_action(x, action, "recipe") 5. │ └─workflows:::validate_is_workflow(x, call = call) 6. │ └─workflows:::is_workflow(x) 7. └─workflows::add_model(., boost_tree() |> set_engine("xgboost")) 8. └─workflows:::new_action_model(spec, formula) 9. └─rlang::abort(message, call = call) [ FAIL 2 | WARN 16 | SKIP 5 | PASS 52 ] Error: Test failures Execution halted ``` -------------------------------- ### Validating Model Specification in workflow Constructor (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/workflow.md This snippet demonstrates the validation of the `spec` argument within the `workflow()` constructor. It shows that `spec` must be a `` object, but a numeric value `1` was provided, leading to an error. ```R workflow(spec = 1) ``` -------------------------------- ### Extracting Parsnip Fit from Untrained Workflow (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/extract.md This snippet shows an attempt to extract a parsnip model fit from an untrained `workflow()` object. The error message suggests that the `fit()` method must be called on the workflow first to train the model before its fit can be extracted. ```R extract_fit_parsnip(workflow()) ``` -------------------------------- ### Preventing Recipe Addition with Existing Formula in tidymodels/workflows (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pre-action-recipe.md This snippet illustrates an error when attempting to add a recipe to a workflow that already contains a formula. The `add_recipe()` function enforces a rule that a workflow can either have a formula or a recipe, but not both simultaneously, to maintain a consistent model specification. ```R add_recipe(workflow, rec) ``` -------------------------------- ### Butchering Untrained tidymodels Workflow (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/butcher.md This snippet demonstrates an attempt to use `butcher::butcher` on an `untrained` tidymodels workflow object. It illustrates the error that arises when a function expecting a fitted model is called on a workflow that has not yet undergone the `fit()` process, indicating that the model within the workflow is not yet trained or available for extraction. ```R butcher::butcher(workflow()) ``` -------------------------------- ### Error Handling: Invalid Input for Workflow Preprocessor Extraction (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pull.md Illustrates an error when `pull_workflow_preprocessor()` is called with an argument that is not a workflow object. The function strictly expects a workflow, but receives a numeric value, leading to a type mismatch error. ```R pull_workflow_preprocessor(1) ``` -------------------------------- ### Error Handling: Extracting Spec from Empty Workflow (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pull.md Demonstrates an error when attempting to extract a model specification from an empty or unconfigured workflow object using `pull_workflow_spec()`. The error indicates that no model specification is attached to the workflow, requiring it to be added first. ```R pull_workflow_spec(workflow()) ``` -------------------------------- ### Preventing Addition of Trained Recipe in tidymodels/workflows (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pre-action-recipe.md This snippet demonstrates an error when trying to add a recipe that has already been trained to a workflow. Workflows expect untransformed or untrained recipes to ensure that the training process (e.g., `prep()` or `fit()`) is managed by the workflow itself, applying transformations consistently. ```R add_recipe(workflow, rec) ``` -------------------------------- ### Invalid Blueprint Type in add_variables (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pre-action-variables.md This snippet demonstrates the error when an unsupported `blueprint` type is passed to `add_variables()`. The function strictly requires the `blueprint` argument to be a `hardhat ` object for proper processing. ```R add_variables(workflow, mpg, cyl, blueprint = blueprint) ``` -------------------------------- ### Adding Variables to Workflow with Existing Recipe (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pre-action-variables.md This snippet demonstrates an error when attempting to add variables to a `tidymodels` workflow that already contains a recipe. The `add_variables()` function prevents this to maintain workflow integrity, ensuring that variable specification is consistent. ```R add_variables(wf, y, x) ``` -------------------------------- ### Handling Case Weights: Recipe Adjusting Column Class (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pre-action-case-weights.md This snippet illustrates an error where the `fit()` function fails if the recipe modifies the class of the case weights column. The column must retain its `hardhat::is_case_weights()` class for the workflow to function correctly. ```R fit(wf, df) ``` -------------------------------- ### Handling Case Weights: Recipe Dropping Column (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pre-action-case-weights.md This snippet demonstrates an error when a tidymodels recipe attempts to drop the case weights column. The `fit()` function fails because no column with the 'case_weights' role is found after recipe processing, indicating that the case weights column must persist. ```R fit(wf, df) ``` -------------------------------- ### Error Handling: Invalid Input for Workflow Mold Extraction (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pull.md Demonstrates an error when `pull_workflow_mold()` is called with an argument that is not a workflow object. The function requires a workflow to extract the mold, but receives a numeric value, leading to a type mismatch error. ```R pull_workflow_mold(1) ``` -------------------------------- ### Fitting Workflow Without Model (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/fit.md This snippet demonstrates an error when trying to fit a workflow that does not have a model defined. The condition `Error in `.fit_pre()`: ! The workflow must have a model. i Provide one with `add_model()`.` advises adding a model using `add_model()`. ```R fit(workflow, mtcars) ``` -------------------------------- ### Adding Model Specification Without Known Mode in tidymodels (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/fit-action-model.md This snippet illustrates an error when a model specification (`mod`) lacks a defined mode. The `add_model()` function requires the `spec` to have a known mode, suggesting the use of `parsnip::set_mode()` or direct mode setting in the parsnip specification function to resolve the issue. ```R add_model(workflow, mod) ``` -------------------------------- ### Extracting Mold with Invalid Input (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/extract.md The `extract_mold()` function, designed for `workflow` objects, is called here with a numeric input. This results in an error, as there is no method defined for extracting a mold from a numeric type. ```R extract_mold(1) ``` -------------------------------- ### Extracting Recipe with Invalid 'estimated' Argument (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/extract.md This snippet demonstrates an incorrect usage of `extract_recipe()`, where the `estimated` argument is provided with a string value instead of a boolean (`TRUE` or `FALSE`). The function strictly requires a logical value for this parameter. ```R extract_recipe(workflow, estimated = "yes please") ``` -------------------------------- ### Extracting Parsnip Spec from Empty Workflow (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/extract.md Calling `extract_spec_parsnip()` on an empty `workflow()` object results in an error. This is because the workflow must have a model specification (e.g., from `set_engine()`) attached before its spec can be extracted. ```R extract_spec_parsnip(workflow()) ``` -------------------------------- ### Deprecation Warning: `pull_workflow_preprocessor()` (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pull.md Shows the deprecation warning for `pull_workflow_preprocessor()`. This function is soft-deprecated in `workflows` version 0.2.3, and users are advised to use `extract_preprocessor()` for future compatibility and improved functionality. ```R x <- pull_workflow_preprocessor(workflow) ``` -------------------------------- ### Validating Trained Argument in new_workflow Constructor (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/workflow.md This snippet highlights the input validation for the `trained` argument in the `new_workflow()` constructor. It mandates that `trained` must be a single logical value, but a numeric value `1` was passed, causing an error. ```R new_workflow(trained = 1) ``` -------------------------------- ### Attempting to Add Variables Multiple Times (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pre-action-variables.md This snippet illustrates the error that occurs when `add_variables()` is called on a workflow that already has a `variables` action defined. A workflow can only have one set of variables specified, whether directly or through `workflow_variables()`. ```R add_variables(workflow, mpg, cyl) ``` ```R add_variables(workflow, variables = workflow_variables(mpg, cyl)) ``` -------------------------------- ### Extracting Parameter Set with Duplicate IDs (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/extract.md This code attempts to extract a parameter set using `extract_parameter_set_dials()` from a workflow (`wflow`) that contains non-unique element IDs. The error indicates that all parameter IDs within the workflow's parameter set must be unique. ```R extract_parameter_set_dials(wflow) ``` -------------------------------- ### Validating Recipe Type in tidymodels/workflows (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pre-action-recipe.md This snippet demonstrates an error when `add_recipe()` is called with an invalid `recipe` argument. The function expects a valid `recipe` object, but receives a numeric value (1), leading to an error indicating that `recipe` must be a recipe object. ```R add_recipe(workflow(), 1) ``` -------------------------------- ### Case Weights: 'col' Argument Multiple Column Selection (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pre-action-case-weights.md This snippet highlights a limitation where the `col` argument for case weights must specify exactly one column from the input `data`. Attempting to select multiple columns for case weights will result in an error. ```R fit(wf, mtcars) ``` -------------------------------- ### Preventing Recipe Addition with Existing Variables in tidymodels/workflows (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pre-action-recipe.md This snippet shows an error when `add_recipe()` is called on a workflow that already has variables defined. Similar to formulas, workflows are designed to accept either a recipe or explicitly defined variables, but not both, to avoid conflicting data preprocessing instructions. ```R add_recipe(workflow, rec) ``` -------------------------------- ### Specifying Model Terms with add_variables() in R Source: https://github.com/tidymodels/workflows/blob/main/NEWS.md This snippet demonstrates how to use the `add_variables()` function within the `workflows` package to specify model terms. It allows for selecting response and predictor variables using `tidyselect` expressions, offering an alternative to the formula method that avoids potential preprocessing issues like class stripping by `model.matrix()` for columns such as Date types. ```R wf <- workflow() %>% add_variables(y, c(var1, start_with("x_"))) %>% add_model(spec_lm) ``` -------------------------------- ### Debugging `modeltime` Test Failures (R) Source: https://github.com/tidymodels/workflows/blob/main/revdep/problems.md This R code snippet displays the backtrace of a test failure within the `modeltime` package. The error originates from an invalid workflow object during the `add_model` or `add_recipe` steps, specifically when adding an `svm_rbf` model or removing a date column from a recipe. It indicates a problem with workflow validation. ```R Running ‘testthat.R’ Running the tests in ‘tests/testthat.R’ failed. Last 13 lines of output: Backtrace: ▆ 1. ├─... |> fit(data_set) at test-panel-data.R:33:0 2. ├─generics::fit(., data_set) 3. ├─workflows::add_recipe(., recipe_spec |> step_rm(date)) 4. │ └─workflows:::add_action(x, action, "recipe") 5. │ └─workflows:::validate_is_workflow(x, call = call) 6. │ └─workflows:::is_workflow(x) 7. └─workflows::add_model(., svm_rbf() |> set_engine("kernlab")) 8. └─workflows:::new_action_model(spec, formula) 9. └─rlang::abort(message, call = call) [ FAIL 2 | WARN 2 | SKIP 22 | PASS 477 ] Error: Test failures Execution halted ``` -------------------------------- ### Missing Data Argument in `fit()` (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/fit.md This snippet demonstrates an error when calling `fit()` on a workflow without providing the required `data` argument. The condition `Error in `fit()`: ! `data` must be provided to fit a workflow.` indicates that `data` must be supplied to train the workflow. ```R fit(workflow) ``` -------------------------------- ### Extracting Parsnip Fit with Invalid Input (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/extract.md This snippet shows `extract_fit_parsnip()` being called with an invalid numeric input. The function expects a `workflow` object, and attempting to use it with a numeric type leads to a 'no applicable method' error. ```R extract_fit_parsnip(1) ``` -------------------------------- ### Deprecation Warning: `pull_workflow_mold()` (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pull.md Shows the deprecation warning for `pull_workflow_mold()`. This function is soft-deprecated in `workflows` version 0.2.3, and users are advised to use `extract_mold()` for future compatibility and improved functionality. ```R x <- pull_workflow_mold(workflow) ``` -------------------------------- ### Adding Variables to Workflow with Existing Formula (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pre-action-variables.md This snippet illustrates an error when `add_variables()` is called on a `tidymodels` workflow that already has a formula defined. The function enforces that variables cannot be added if a formula-based specification is already present. ```R add_variables(wf, y, x) ``` -------------------------------- ### Attempting to Add Multiple Models to a Single tidymodels Workflow (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/fit-action-model.md This snippet illustrates an error when attempting to add a second model to a tidymodels workflow that already contains a model action. The `add_model()` function enforces that only one model specification can be associated with a workflow at a time. ```R add_model(workflow, mod) ``` -------------------------------- ### Validating Formula Input in add_formula() (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pre-action-formula.md This snippet demonstrates the validation of the `formula` argument in `add_formula()`. It shows that providing a non-formula input (like `1`) results in an error, indicating that the argument must be a valid R formula. ```R add_formula(workflow(), 1) ``` -------------------------------- ### Validating Workflow Argument in add_model (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/workflow.md This snippet highlights the input validation for the `add_model()` function. It mandates that the first argument `x` must be a `workflow` object, but a numeric value `1` was passed, causing an error. ```R add_model(1, mod) ``` -------------------------------- ### Validating Workflow Argument in add_formula (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/workflow.md This snippet demonstrates the input validation for the `add_formula()` function. It shows that the first argument `x` must be a `workflow` object, but a numeric value `1` was provided, leading to an error. ```R add_formula(1, mpg ~ cyl) ``` -------------------------------- ### Error Handling: Invalid Input for Workflow Fit Extraction (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pull.md Highlights an error when `pull_workflow_fit()` is used with an argument that is not a workflow. The function expects a workflow object to extract the fit, but a numeric value is passed, causing a type mismatch. ```R pull_workflow_fit(1) ``` -------------------------------- ### Extracting Parsnip Spec with Invalid Input (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/extract.md Similar to other `extract_*` functions, `extract_spec_parsnip()` requires a `workflow` object. Providing a numeric value (1) results in an error, as no applicable method exists for that class. ```R extract_spec_parsnip(1) ``` -------------------------------- ### Invalid Control Argument in `fit()` (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/fit.md This snippet shows an error when an invalid `control` object is passed to `fit()`. The condition `Error in `fit()`: ! `control` must be a workflows control object created by `control_workflow()`.` clarifies that `control` must be a `workflows` control object created by `control_workflow()`. ```R fit(workflow, mtcars, control = control) ``` -------------------------------- ### Deprecation Warning: `pull_workflow_fit()` (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pull.md Shows the deprecation warning for `pull_workflow_fit()`. This function is soft-deprecated in `workflows` version 0.2.3, and users are advised to use `extract_fit_parsnip()` for future compatibility and improved functionality. ```R x <- pull_workflow_fit(workflow) ``` -------------------------------- ### Handling Case Weights: Recipe Changing Column Name (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pre-action-case-weights.md This snippet shows an error when a tidymodels recipe renames the case weights column. The `fit()` function fails because it cannot find the original case weights column by its expected name after recipe processing. ```R fit(wf, df) ``` -------------------------------- ### Missing Predictors Argument in add_variables (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pre-action-variables.md This snippet shows the error encountered when `add_variables()` is called with only the `outcomes` argument provided, but `predictors` is missing. The function requires both `predictors` and `outcomes` to be specified for a complete variable definition. ```R add_variables(workflow(), outcomes = mpg) ``` -------------------------------- ### Defining a Bayesian Linear Regression Model in R Source: https://github.com/tidymodels/workflows/blob/main/README.md This R snippet defines a Bayesian linear regression model using the 'parsnip' package. It sets the engine for the model to 'stan', indicating that the model will be fitted using the Stan probabilistic programming language. ```R bayes_lm <- linear_reg() |> set_engine("stan") ``` -------------------------------- ### Preventing Multiple Postprocessors in tidymodels R Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/post-action-tailor.md This snippet illustrates the error encountered when trying to add a second `tailor` action to a tidymodels workflow that already has one. The `add_tailor()` function enforces a single postprocessor per workflow, preventing duplicate actions. ```R add_tailor(workflow, post) ``` -------------------------------- ### Missing Outcomes Argument in add_variables (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pre-action-variables.md This snippet demonstrates the error when `add_variables()` is invoked with only the `predictors` argument, but `outcomes` is missing. Both `predictors` and `outcomes` are mandatory arguments for defining variables in a workflow. ```R add_variables(workflow(), predictors = mpg) ``` -------------------------------- ### Validating Postprocessor Type in tidymodels R Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/post-action-tailor.md This snippet demonstrates the validation error when attempting to add a non-`tailor` object as a postprocessor to a tidymodels workflow. The `add_tailor()` function expects its second argument to be a valid `tailor` object, ensuring type correctness. ```R add_tailor(workflow(), 1) ``` -------------------------------- ### Deprecation Warning: `pull_workflow_spec()` (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pull.md Shows the deprecation warning for `pull_workflow_spec()`. This function is soft-deprecated in `workflows` version 0.2.3, and users are advised to use `extract_spec_parsnip()` for future compatibility and improved functionality. ```R x <- pull_workflow_spec(workflow) ``` -------------------------------- ### Error Handling: Invalid Input for Workflow Spec Extraction (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pull.md Shows an error when `pull_workflow_spec()` is invoked with a non-workflow argument. The function requires a workflow object for proper operation, but a numeric value is provided, resulting in a type error. ```R pull_workflow_spec(1) ``` -------------------------------- ### Adding Invalid Model Specification to tidymodels Workflow (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/fit-action-model.md This snippet demonstrates an error when attempting to add an invalid object (a numeric value `1`) as a model specification to a tidymodels workflow. The `add_model()` function expects a `` object, leading to an error if an incorrect type is provided. ```R add_model(workflow(), 1) ``` -------------------------------- ### Demonstrating Invalid `control_parsnip` Argument in R Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/control.md This code snippet illustrates an attempt to call `control_workflow` with an invalid type for the `control_parsnip` argument. It shows that passing a numeric value (e.g., `1`) instead of a `control_parsnip` object will result in a validation error, enforcing type safety within `tidymodels` workflows. ```R control_workflow(control_parsnip = 1) ``` -------------------------------- ### Preventing Formula Addition with Existing Variables in add_formula() (R) Source: https://github.com/tidymodels/workflows/blob/main/tests/testthat/_snaps/pre-action-formula.md This snippet highlights another restriction: `add_formula()` cannot be used if variables have already been specified in the workflow. This ensures that the method for defining model predictors and outcomes is consistent and avoids conflicts. ```R add_formula(workflow, mpg ~ cyl) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.