From 746b473f8151b3c361b3c50560f2d9a68c285c22 Mon Sep 17 00:00:00 2001 From: "Simon P. Couch" Date: Wed, 8 Nov 2023 10:21:07 -0600 Subject: [PATCH] link to info on model formulas in error message (#1257) --- DESCRIPTION | 4 +++- R/recipe.R | 8 +++++--- man/recipe.Rd | 16 ++++++++-------- man/selections.Rd | 18 +++++++++--------- tests/testthat/_snaps/basics.md | 16 ++++++++-------- 5 files changed, 33 insertions(+), 29 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5997fbdf1..8d25d5d9d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -52,7 +52,7 @@ Suggests: kernlab, knitr, modeldata (>= 0.1.1), - parsnip (>= 0.1.7), + parsnip (>= 1.1.1.9001), RANN, RcppRoll, rmarkdown, @@ -72,3 +72,5 @@ Config/testthat/edition: 3 Encoding: UTF-8 Roxygen: list(markdown = TRUE) RoxygenNote: 7.2.3 +Remotes: + tidymodels/parsnip diff --git a/R/recipe.R b/R/recipe.R index 2f8960a76..9a211295b 100644 --- a/R/recipe.R +++ b/R/recipe.R @@ -279,9 +279,11 @@ inline_check <- function(x) { cli::cli_abort(c( x = "No in-line functions should be used here.", i = "{cli::qty(length(funs))}The following function{?s} {?was/were} \\ - found:", - "*" = "{.and {.code {funs}}}", - i = "Use steps to do transformations instead." + found: {.and {.code {funs}}}.", + i = "Use steps to do transformations instead.", + i = "If your modeling engine uses special terms in formulas, pass \\ + that formula to workflows as a \\ + {.help [model formula](parsnip::model_formula)}." )) } diff --git a/man/recipe.Rd b/man/recipe.Rd index 7d294c445..09c6b064f 100644 --- a/man/recipe.Rd +++ b/man/recipe.Rd @@ -80,8 +80,8 @@ added to a recipe. \itemize{ \item \strong{Steps} can include operations like scaling a variable, creating dummy variables or interactions, and so on. More computationally -complex actions such as dimension reduction or imputation can also -be specified. +complex actions such as dimension reduction or imputation can also be +specified. \item \strong{Checks} are operations that conduct specific tests of the data. When the test is satisfied, the data are returned without issue or modification. Otherwise, an error is thrown. @@ -300,12 +300,12 @@ applies the estimated steps to any data set. \if{html}{\out{
}}\preformatted{## # A tibble: 6 x 6 ## HHV PC1 PC2 PC3 PC4 PC5 ## -## 1 18.3 0.730 0.412 0.495 0.333 0.253 -## 2 17.6 0.617 -1.41 -0.118 -0.466 0.815 -## 3 17.2 0.761 -1.10 0.0550 -0.397 0.747 -## 4 18.9 0.0400 -0.950 -0.158 0.405 -0.143 -## 5 20.5 0.792 0.732 -0.204 0.465 -0.148 -## 6 18.5 0.433 0.127 0.354 -0.0168 -0.0888 +## 1 18.3 0.730 -0.412 -0.495 0.333 0.253 +## 2 17.6 0.617 1.41 0.118 -0.466 0.815 +## 3 17.2 0.761 1.10 -0.0550 -0.397 0.747 +## 4 18.9 0.0400 0.950 0.158 0.405 -0.143 +## 5 20.5 0.792 -0.732 0.204 0.465 -0.148 +## 6 18.5 0.433 -0.127 -0.354 -0.0168 -0.0888 }\if{html}{\out{
}} In general, the workflow interface to recipes is recommended for most diff --git a/man/selections.Rd b/man/selections.Rd index cfbe6b5d1..19d696cb0 100644 --- a/man/selections.Rd +++ b/man/selections.Rd @@ -111,20 +111,20 @@ will not work. When creating variable selections: \itemize{ -\item If you are using column filtering steps, such as \code{step_corr()}, try -to avoid hardcoding specific variable names in downstream steps in -case those columns are removed by the filter. Instead, use +\item If you are using column filtering steps, such as \code{step_corr()}, try to +avoid hardcoding specific variable names in downstream steps in case +those columns are removed by the filter. Instead, use \code{\link[dplyr:reexports]{dplyr::any_of()}} and \code{\link[dplyr:reexports]{dplyr::all_of()}}. \itemize{ -\item \code{\link[dplyr:reexports]{dplyr::any_of()}} will be tolerant if a -column has been removed. +\item \code{\link[dplyr:reexports]{dplyr::any_of()}} will be tolerant if a column +has been removed. \item \code{\link[dplyr:reexports]{dplyr::all_of()}} will fail unless all of the columns are present in the data. } -\item For both of these functions, if you are going to save the recipe as -a binary object to use in another R session, try to avoid referring -to a vector in your workspace. +\item For both of these functions, if you are going to save the recipe as a +binary object to use in another R session, try to avoid referring to a +vector in your workspace. \itemize{ \item Preferred: \code{any_of(!!var_names)} \item Avoid: \code{any_of(var_names)} @@ -155,7 +155,7 @@ recipe(mpg ~ ., data = mtcars) \%>\% }\if{html}{\out{}} \if{html}{\out{
}}\preformatted{## Error in `step_log()`: -## Caused by error in `prep()` at recipes/R/recipe.R:437:8: +## Caused by error in `prep()` at recipes/R/recipe.R:473:8: ## ! Can't subset columns that don't exist. ## x Column `wt` doesn't exist. }\if{html}{\out{
}} diff --git a/tests/testthat/_snaps/basics.md b/tests/testthat/_snaps/basics.md index 2d271121c..ab3a5fe9e 100644 --- a/tests/testthat/_snaps/basics.md +++ b/tests/testthat/_snaps/basics.md @@ -5,9 +5,9 @@ Condition Error in `inline_check()`: x No in-line functions should be used here. - i The following function was found: - * `log` + i The following function was found: `log`. i Use steps to do transformations instead. + i If your modeling engine uses special terms in formulas, pass that formula to workflows as a model formula (`?parsnip::model_formula()`). --- @@ -16,9 +16,9 @@ Condition Error in `inline_check()`: x No in-line functions should be used here. - i The following functions were found: - * `^` and `(` + i The following functions were found: `^` and `(`. i Use steps to do transformations instead. + i If your modeling engine uses special terms in formulas, pass that formula to workflows as a model formula (`?parsnip::model_formula()`). --- @@ -27,9 +27,9 @@ Condition Error in `inline_check()`: x No in-line functions should be used here. - i The following function was found: - * `:` + i The following function was found: `:`. i Use steps to do transformations instead. + i If your modeling engine uses special terms in formulas, pass that formula to workflows as a model formula (`?parsnip::model_formula()`). --- @@ -38,9 +38,9 @@ Condition Error in `inline_check()`: x No in-line functions should be used here. - i The following function was found: - * `^` + i The following function was found: `^`. i Use steps to do transformations instead. + i If your modeling engine uses special terms in formulas, pass that formula to workflows as a model formula (`?parsnip::model_formula()`). # Using prepare