require(pacman)

rpart_imp <- function(x, y, ...) {
  p_load(rpart)
  data = data.frame(x, y)
  fit <- rpart(y ~ ., data = data, ...)
  imp = fit$variable.importance
  imp = imp[xvars]
  imp[is.na(imp)] = 0
  names(imp) = xvars
  list(errRank = imp_measure(imp[xvars]), 
       imp = imp_scale(imp[xvars]),
       oimp = imp[xvars],
       mi = names(which.max(imp)))
}

test_rpart <- function() {
  p_load(rpart)
  z.auto <- rpart(Mileage ~ ., car.test.frame)
  return(z.auto)
}
