Skip to content

add conditionMessage method for recipes_errors #1080

Description

@simonpcouch

I’m very much appreciating recipes pointing out which step errors occurred in following #1069. We unfortunately don’t get the benefits of those changes in tune (and possibly other packages that need to catch and rethrow errors from recipes, see tidymodels/tune#599), as dispatch falls back to the rlang_error method for conditionMessage():

library(recipes)

data("ames", package = "modeldata")

err <- try(
  recipe(~., data = ames) |>
  step_novel(Neighborhood, new_level = "Gilbert") |>
  prep()
)
#> Error in step_novel() : 
#> Caused by error in `prep()`:
#> ! Columns already contain the new level: Neighborhood

err_cnd <- attr(err, "condition")

class(err_cnd)
#> [1] "recipes_error_step" "recipes_error"      "rlang_error"       
#> [4] "error"              "condition"

conditionMessage(err_cnd)
#> [1] "\nCaused by error in `prep()`:\n! Columns already contain the new level: Neighborhood"

Could we add a conditionMessage method that precedes the current conditionMessage() output with “Error in step_*”?

Created on 2023-01-20 with reprex v2.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions