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

> ### Name: shap.prep
> ### Title: Prepare SHAP values into long format for plotting
> ### Aliases: shap.prep
> 
> ### ** Examples
> 
> data("iris")
> X1 = as.matrix(iris[,-5])
> mod1 = xgboost::xgboost(
+   data = X1, label = iris$Species, gamma = 0, eta = 1,
+   lambda = 0, nrounds = 1, verbose = FALSE)
> 
> # shap.values(model, X_dataset) returns the SHAP
> # data matrix and ranked features by mean|SHAP|
> shap_values <- shap.values(xgb_model = mod1, X_train = X1)
> shap_values$mean_shap_score
Petal.Length  Petal.Width Sepal.Length  Sepal.Width 
  0.62935975   0.21664035   0.02910357   0.00000000 
> shap_values_iris <- shap_values$shap_score
> 
> # shap.prep() returns the long-format SHAP data from either model or
> shap_long_iris <- shap.prep(xgb_model = mod1, X_train = X1)
> # is the same as: using given shap_contrib
> shap_long_iris <- shap.prep(shap_contrib = shap_values_iris, X_train = X1)
> 
> # **SHAP summary plot**
> shap.plot.summary(shap_long_iris, scientific = TRUE)
> shap.plot.summary(shap_long_iris, x_bound  = 1.5, dilute = 10)
> 
> # Alternatives options to make the same plot:
> # option 1: from the xgboost model
> shap.plot.summary.wrap1(mod1, X = as.matrix(iris[,-5]), top_n = 3)
> 
> # option 2: supply a self-made SHAP values dataset
> # (e.g. sometimes as output from cross-validation)
> shap.plot.summary.wrap2(shap_score = shap_values_iris, X = X1, top_n = 3)
> ####
> #
> # use `var_cat` to add a categorical variable, output the long-format data differently:
> library("data.table")
> data("iris")
> set.seed(123)
> iris$Group <- 0
> iris[sample(1:nrow(iris), nrow(iris)/2), "Group"] <- 1
> 
> data.table::setDT(iris)
> X_train = as.matrix(iris[,c(colnames(iris)[1:4], "Group"), with = FALSE])
> mod1 = xgboost::xgboost(
+   data = X_train, label = iris$Species, gamma = 0, eta = 1,
+   lambda = 0, nrounds = 1, verbose = FALSE)
> 
> shap_long2 <- shap.prep(xgb_model = mod1, X_train = X_train, var_cat = "Group")
> # **SHAP summary plot**
> shap.plot.summary(shap_long2, scientific = TRUE) +
+   ggplot2::facet_wrap(~ Group)
> # **LightGBM**
> 
> mod_lgb = lightgbm::lgb.train(
+   params = list(objective = "regression"),
+   data = lightgbm::lgb.Dataset(data.matrix(iris[, -1]),
+                                label = iris[[1]]),
+   nrounds = 10,
+   verbose = -2
+ )