Skip to content

Surface erroring function in collect_notes() when coming from base functions #873

Description

@EmilHvitfeldt

non-minimal reprex:

The error factor Categorical_Predictor has new levels new comes from model.frame.default() but it is hard to figure that out right now

# Create sample data
library(tidymodels)

set.seed(123)
num_samples <- 100
outcome <- rnorm(num_samples, mean = 50, sd = 10)
categorical_predictor <- as.factor(sample(letters[1:4], num_samples, replace = TRUE))

# Create dataframe
df <- data.frame(
  Outcome = outcome,
  Categorical_Predictor = categorical_predictor
)

new_row <- data.frame(
  Outcome = 55,
  Categorical_Predictor = "problem"
)

# Add the new row to the dataframe
df <- rbind(new_row, df)

lr_full_preprocessing <- 
  recipe(Outcome ~ ., data = df) %>%
  # novel categories
  step_novel(all_nominal_predictors())

lr_full <- linear_reg() %>%
  set_engine("lm")

lr_full_wf <- workflow() %>%
  add_recipe(lr_full_preprocessing, blueprint = hardhat::default_recipe_blueprint(allow_novel_levels = FALSE)) %>%
  add_model(lr_full)

set.seed(123)  # for reproducibility
folds <- vfold_cv(df, v = 2, repeats = 1)

lr_full_fit_rs <- lr_full_wf %>% 
  fit_resamples(folds)
#> → A | error:   factor Categorical_Predictor has new levels new
#> There were issues with some computations   A: x1
#> There were issues with some computations   A: x1
#> 

collect_notes(lr_full_fit_rs) %>%
  glimpse()
#> Rows: 1
#> Columns: 4
#> $ id       <chr> "Fold1"
#> $ location <chr> "preprocessor 1/1, model 1/1 (predictions)"
#> $ type     <chr> "error"
#> $ note     <chr> "factor Categorical_Predictor has new levels new"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions