Xgb.shap.data not found


When I try using the xgb.shap.data function in R I receive the following error message:

Error in xgb.shap.data(bstSparse) : could not find function “xgb.shap.data”

I have tried this with both simple and complex xgb models and I get the same error. I am running the latest version of R (4.1.2) through RStudio on a Windows 10 (64 bit) machine, and I just updated my version of xgboost to Here’s a simple (hopefully, reproduceable) example of the error:

data(agaricus.train, package=‘xgboost’)
data(agaricus.test, package=‘xgboost’)
train <- agaricus.train
test <- agaricus.test

bstSparse <- xgboost(data = train$data,
label = train$label,
max_depth = 2,
eta = 1,
nthread = 2,
nrounds = 2,
objective = “binary:logistic”,
eval_metric = “logloss”


Error in xgb.shap.data(bstSparse) :
could not find function “xgb.shap.data”

Any help resolving this working would be much appreciated!

Can you try using xgboost::xgb.shap.data?

Hi Philip,

Thank you for the reply. I just ran: xgboost::xgb.shap.data(bstSparse)
and I get:
Error: ‘xgb.shap.data’ is not an exported object from ‘namespace:xgboost’

xgb.shap.data was not exported correctly. I will investigate. In the meanwhile, please use xgboost:::xgb.shap.data (notice the three colons).

I submitted https://github.com/dmlc/xgboost/pull/7471 to make xgb.shap.data visible. It will be part of the next release.

Great, thank you for taking care of this so quickly!