I think there is delayed evaluation of the inputs.
The default for tree_depth for boosted trees is 6L, when you use explicit NULL, tidymodels substitutes 6 and so can compute last_fit.
When you provide NULL in a depth variable, this had a delayed evaluation, and therefore seems to avoid being substituted for 6 is my guess. You can try the injection operator from rlang.
myfunc <- function(x){
a <- rlang::enquo(x)
cat("thanks for that will consider ",rlang::as_label(a))
}
myfunc(NULL)
foo <- NULL
myfunc(foo)
myfunc(!!foo)
i.e.
xg_model <-
boost_tree(
trees = 1000,
tree_depth = !!depth # Directly passing in NULL works fine
) %>%
set_engine("xgboost") %>%
set_mode("classification")