
require(pacman)

rf_imp <- function(x, y, ...)  {
  require(randomForest)
  p_load(caret)

  data = data.frame(x, y)
  
  fit <- randomForest(y ~ ., data = data, importance = TRUE, ...)
  errImp = randomForest::importance(fit, type = 1)
  nodeImp = randomForest::importance(fit, type = 2)
  
  errRank = imp_measure(errImp)
  nodeRank = imp_measure(nodeImp)
  
  return(list(errRank = errRank, imp = imp_scale(errImp[,1]),
              oimp = errImp[,1],
              nodeImp = imp_scale(nodeImp[,1])))
}