'Predict xgboost model onto raster stack yields error

I am using an xgboost model to predict onto a raster stack. I have successfully used the same approach with CART, xgb and Random Forest models:

r_xgboost <- raster::predict(model = xgboost, object = r)

But with xgboost I get the following error:

Error in xgb.DMatrix(newdata, missing = missing) : 
  xgb.DMatrix does not support construction from list


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source