Running examples in 'MLDataR-Ex.R' failed
The error most likely occurred in:

> ### Name: long_stayers
> ### Title: Long stayers dataset
> ### Aliases: long_stayers
> ### Keywords: NHS long patient stay stranded
> 
> ### ** Examples
> 
> library(dplyr)

Attaching package: 'dplyr'

The following objects are masked from 'package:stats':

    filter, lag

The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union

> library(ggplot2)
> library(caret)
Loading required package: lattice
> library(rsample)
> library(varhandle)
> data("long_stayers")
> glimpse(long_stayers)
Rows: 768
Columns: 9
$ stranded.label           <chr> "Not Stranded", "Not Stranded", "Not Stranded…
$ age                      <int> 50, 31, 32, 69, 33, 75, 26, 64, 53, 63, 30, 7…
$ care.home.referral       <int> 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, …
$ medicallysafe            <int> 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, …
$ hcop                     <int> 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, …
$ mental_health_care       <int> 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, …
$ periods_of_previous_care <int> 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 1, 1, 1, 1, 4, …
$ admit_date               <chr> "29/12/2020", "11/12/2020", "19/01/2021", "07…
$ frailty_index            <chr> "No index item", "No index item", "No index i…
> # Examine class imbalance
> prop.table(table(long_stayers$stranded.label))

Not Stranded     Stranded 
   0.5963542    0.4036458 
> # Feature engineering
> long_stayers <- long_stayers %>%
+ dplyr::mutate(stranded.label=factor(stranded.label)) %>%
+  dplyr::select(everything(), -c(admit_date))
>  # Feature encoding
>  cats <- select_if(long_stayers, is.character)
>  cat_dummy <- varhandle::to.dummy(cats$frailty_index, "frail_ind")
> #Converts the frailty index column to dummy encoding and sets a column called "frail_ind" prefix
> cat_dummy <- cat_dummy %>%
+  as.data.frame() %>%
+  dplyr::select(-frail_ind.No_index_item) #Drop the field of interest
> long_stayers <- long_stayers %>%
+  dplyr::select(-frailty_index) %>%
+  bind_cols(cat_dummy) %>% na.omit(.)
> # Split the data
> split <- rsample::initial_split(long_stayers, prop = 3/4)
> train <- rsample::training(split)
> test <- rsample::testing(split)
> set.seed(123)
> glm_class_mod <- caret::train(factor(stranded.label) ~ ., data = train,
+                              method = "glm")