inst/tinytest/test_pkg_rpart.R

# Exits
if (!requireNamespace("rpart", quietly = TRUE)) {
  exit_file("Package 'rpart' missing")
}

# # Load required packages
# suppressMessages({
#   library(rpart)
# })

# Generate Friedman benchmark data
friedman1 <- gen_friedman(seed = 101)

# Fit model(s)
fit <- rpart::rpart(y ~ ., data = friedman1)
no_splits <- rpart::rpart(y ~ ., data = friedman1, minsplit = 1e06)

# Compute VI scores
vis <- vi_model(fit)

# Expectations for `vi_model()`
expect_identical(
  current = vis$Importance,
  target = unname(fit$variable.importance)
)
expect_error(vi(no_splits))

# Expectations for `get_feature_names()`
expect_identical(
  current = vip:::get_feature_names.rpart(fit),
  target = paste0("x", 1L:10L)
)

Try the vip package in your browser

Any scripts or data that you put into this service are public.

vip documentation built on Aug. 21, 2023, 5:12 p.m.