Results for prediction in glmnet

Hello to all,

I have been using the excellent parsnip package, and running some simulations to assess the effects of changing the regularization parameter. Now, there are cases in which I get an error but it appears sporadically.

This even though in all the simulations I am using the same penalty value of 10. Here post I reproducible example, all the simulations run smoothly but for some reason, the 120th simulation (that uses the same data generating process and parametrization) leads to an error the error.

library(tidymodels)
asses_cv<-1
n_folds<-1
pen_val<-seq(from=10,to=10,length.out=1)
tuning_g<-expand_grid(penalty=pen_val,mixture=c(1))
for (i in 1:120){
  set.seed(i)
  x1<-rnorm(100)
  x2<-rnorm(100)
  y<-3+rnorm(100)
  
  train<-tibble(y,x1,x2)
  lm_elne<-linear_reg(penalty = tune(),mixture = tune()) %>%
    set_engine("glmnet",path_values = pen_val,thresh=1E-25)
  
  rec<-recipe(y~.,train)
  
  folds<-rolling_origin(train,initial = (NROW(train)-n_folds-asses_cv+1),assess = asses_cv)
  
  wf_elne<-workflow() %>%
    add_model(lm_elne) %>%
    add_recipe(rec)
  
  lm_elne_res<-tune_grid(wf_elne,resamples=folds,grid=tuning_g,metrics = yardstick::metric_set(rmse))
  
  wf_elne %>%
    finalize_workflow(select_best(lm_elne_res,metric = "rmse")) %>%
    fit(train) %>%
    predict(train[1,])
}
#> Error in `.check_glmnet_penalty_predict()`:
#> ! The glmnet model was fit with a single penalty value of 10. Predicting with a value of 10 will give incorrect results from `glmnet()`.

Created on 2024-12-03 with reprex v2.1.1

I would appreciate any comment or advice. Thank you very much.