tidymodels / recipes

Pipeable steps for feature engineering and data preprocessing to prepare for modeling
https://recipes.tidymodels.org
Other
560 stars 112 forks source link

issues making splines with single row data frames #1191

Closed topepo closed 1 year ago

topepo commented 1 year ago

First seen in tidymodels/TMwR#367

library(tidymodels)

tidymodels_prefer()
theme_set(theme_bw())
options(pillar.advice = FALSE, pillar.min_title_chars = Inf)

ns_rec <- 
  recipe(mpg ~ ., data = mtcars) %>% 
  step_ns(disp, deg_free = 3) %>% 
  prep()

bake(ns_rec, mtcars %>% slice(1))
#> Error in if (num < 1) {: argument is of length zero

ns2_rec <- 
  recipe(mpg ~ ., data = mtcars) %>% 
  step_spline_natural(disp, deg_free = 3) %>% 
  prep()

bake(ns2_rec, mtcars %>% slice(1))
#> Error in if (num < 1) {: argument is of length zero

Created on 2023-08-25 with reprex v2.0.2

For step_ns(), it is an issue with stripping off attributes (I assume the dim attribute).

For step_spline_natrual(), it is using I() rowwise that is dropping the dimension.

github-actions[bot] commented 11 months ago

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex https://reprex.tidyverse.org) and link to this issue.